I am trying to replace the values in data frame with frequency.
Here is my data:
blah<-list(c(1,1,2,2,3,1,3,2,2,5,5), c(7,8,7,8,9,9,7,8,9,7,7))
blah<-as.data.frame(blah)
colnames(blah)<-c("col1","col2")
I have created a table with two columns.
Next, I use “table” to generate the frequency for both columns:
col1Freq<-table(blah[,1])/dim(blah)[1]
col2Freq<-table(blah[,2])/dim(blah)[1]
My goal is to replace all the values in blah to frequencies. So the final table should be the same size as blah, but I want frequencies instead of integers.
Sorry I don’t have any pics to show…. Thanks for your help!!!!
If I correctly understand your question, the base R function
ave()(pay no attention to its misleading name) will do what you’re looking for.