我执行了以下代码:
df<-data.frame(word=c("play","win","offer","http"),frequency=c(321,355,123,564),type=c("nonspam","nonspam","spam","spam"))
df=arrange(df,desc(frequency),desc(type))
df=df[order(df[,2],df[,3]),]
结果如下:
word frequency type
4 offer 123 spam
3 play 321 nonspam
2 win 355 nonspam
1 http 564 spam
但我希望按照频率和类型对数据框进行排序,例如:
word frequency type
1 http 564 spam
4 offer 123 spam
2 win 355 nonspam
3 play 321 nonspam
arrange(df, desc(type), desc(frequency))
- thelatemaildf[order(df$type, df$frequency, decreasing = TRUE),]
- Ronak Shah