5
I need to count the equal values of a column in a data frame (database with the total name) and store the total in a column of another data frame (database with the unique name) that contains the unique values of the first data frame. Soon the two seats are of different sizes, the first is larger than the second. For this I used the code below, but R shows the error that the size of the data frames are different.
y <- c(1,2,3,4,5,6,7,8)
espaco_amostral<-data.frame(t(combn(y,m=4))) #Banco com a combinação do vetor y.
total_amostral<-data.frame(TOTAL=apply(espaco_amostral,1,sum)) #Banco com o somatórios das linhas do espaco_amostral.
unicos<-data.frame(unique(total_amostral)) #banco com valores únicos de total_amostral
contador<-0
for(i in unicos){
for(e in total_amostral){
ifelse(total_amostral[e,] == unicos[i,],
unicos[,2]<-contador+1,unicos[,2]<-0)
}
}
unicos
I believe that in total_amostral[e,] == unicos[i,]
it is comparing the entire banks. How can I make it compare each element of the bank total_amostral
with the unicos
and then tell?
data.table
never disappoints when it comes to performance– Tomás Barcellos
Yes, it’s pretty fast. Here’s a comparison with other alternatives (including python and Spark): https://twitter.com/MattDowle/status/1074746218645938176
– JdeMello