Tac Tacelosky
Tac Tacelosky

Reputation: 3426

How do I get a list, sorted by frequency, in R

I'm trying to get a list, sorted by frequency, from a data frame.

data <- read.csv('ads.csv')
write.table(summary(data$Publication.Name), quote = FALSE, sep = ",")

I'm not sure summary() is really the best way to get frequencies, I'm open to a better way. How can I sort this by most frequent first?

Upvotes: 13

Views: 39095

Answers (1)

ndr
ndr

Reputation: 1437

I would use table, for example

yourdata <- sample(1:10,100,replace=T) 
x <- sort(table(yourdata),decreasing=T)
write.csv(x,"mytable.csv",quote=F)

Upvotes: 27

Related Questions