Advertisement
elena1234

Order in Asc and Dsc

Apr 6th, 2022
1,767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.34 KB | None | 0 0
  1. days <- c('Mon', 'Tue', 'Wed', 'Thur', 'Fri')
  2. temp <- c(20, 30, 20, 24, 25)
  3. rain <- c(T, F, F, F, T)
  4. df <- data.frame(days, temp, rain)
  5. print(df)
  6.  
  7. sorted.temp <- order(df['temp'])
  8. print(sorted.temp)
  9. new.df <- df[sorted.temp, ]
  10. print(new.df)
  11.  
  12. desc.sorted.temp <- order(-df['temp'])
  13. new.df.desc <- df[desc.sorted.temp, ]
  14. print(new.df.desc)
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement