Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sorting

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?

like image 405
Tac Tacelosky Avatar asked Nov 01 '13 12:11

Tac Tacelosky


People also ask

How do you sort a frequency table?

Select the data range. Go to Data tab > Sort option. Sort dialog box will appear. In the sort by, select Frequency of product.

How do I sort by order in R?

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.

How do you find the frequency distribution table in R?

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.


1 Answers

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)
like image 72
ndr Avatar answered Oct 05 '22 14:10

ndr