I'm trying to filter a variable by removing NA's, then table the variable, and then sort by descending. I've tried the following
library(dplyr)
df %>% filter(!is.na(var)) %>% data.frame(sort(table(var),decreasing=TRUE))
Any idea how to get this to work?
The pipe passes the result of the function call on the left as the first argument to the function on the right. Here you've tried to explicitly supply the argument to data.frame
instead, so it will error. Instead, try this:
df %>%
filter(!is.na(var)) %>%
count(var) %>%
arrange(desc(n))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.