I wanted to use a pipe to take a mean of a column from some data in a package, and was surprised when I could not.
At first I thought it had to do with piping, but apparently it was because the df column needed to be unlisted before taking the mean. Is it possible to pipe data from a df/tibble directly to a mean function without de-listing first?
install.packages("UsingR")
library(UsingR)
library(dplyr)
father.son %>%
filter(round(fheight) == 71) %>%
select(sheight) %>% mean
[1] NA
Warning message:
In mean.default(.) : argument is not numeric or logical: returning NA
When I pipe all that into a new object and unlist it, I can take the mean; can I do that right from the pipe?
s <- father.son %>%
filter(round(fheight) == 71) %>%
select(sheight)
mean(unlist(s))
> mean(unlist(s))
[1] 70.54082