I'm trying to calculate the mean of a column of a dataframe using some restrictions so first I did:
mean(Ykkonen$deltaA[Ykkonen$PH<=2.5], na.rm = TRUE)
but I when I try instead
Ykkonen %>% filter(PH<=2.5) %>% mean(deltaA, na.rm = TRUE)
I get error
[1] NA
Warning message:
In mean.default(., deltaA) :
argument is not numeric or logical: returning NA
Yet deltaA
is numerical. So I am trying to understand why using the tubes %>%
is any different?
I mean if I understand it correctly by typing dataframe %>% filter(a=='s')
it should return only entries that has s
for the variable a
, am I right?