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?
Select the data range. Go to Data tab > Sort option. Sort dialog box will appear. In the sort by, select Frequency of product.
To sort a data frame in R, use the order( ) function. By default, sorting is ASCENDING. Prepend the sorting variable by a minus sign to indicate DESCENDING order.
The cumsum() function can be used to calculate this. Relative frequency also known as the probability distribution, is the frequency of the corresponding value divided by the total number of elements. This can be calculated by either prop. table() method applied over the frequency table.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With