0
penguins %>% 
  select(bill_length_mm) %>% 
filter(!is.na(bill_length_mm)) %>% 
  mean(as.numeric(bill_length_mm), na.rm=TRUE)

Error message: argument is not numeric or logical: returning NA[1] NA

Examining the dataset after filtering shows numeric data with no NAs.
Why am I getting this error? Shouldn't line two or line three of the code remove all NAs?

Thank you.

4

1 回答 1

1

尝试换行meansummarize比如

penguins %>% 
  select(bill_length_mm) %>% 
filter(!is.na(bill_length_mm)) %>% 
  summarize(mean(as.numeric(bill_length_mm), na.rm=TRUE))

发生这种情况是因为mean需要一个向量,但您正在传递一个数据帧(来自管道)。

于 2021-08-21T04:40:17.890 回答