A very simply data frame (labeled birdData) as I'm trying to get a good grasp on the fundamentals
bird_sp wingspan
1 sparrow 22
2 kingfisher 26
3 eagle 195
4 hummingbird 8
5 sparrow 24
6 kingfisher 23
7 eagle 201
8 hummingbird 9
9 sparrow 21
10 kingfisher 25
11 eagle 185
12 hummingbird 9
I then tried to use a pipe to filter all the values for sparrow and save the mean value of the wingspan.
sparrowsAvg <- birdData %>%
filter(bird_sp == "sparrow") %>%
mean(sparrowsAvg$wingspan)
print(sparrowsAvg)
I keep getting a return of NA. Chat GPT is telling me that since I used filter I NEED to use the summary function and then nest mean inside of it. I don't quite understand what the summary function does or why I need to use it after filtering in a pipe like this?
Can anyone provide me any insight into what exactly it is that my code is doing and why it is doing that? Furthermore can anyone explain when and why to use summary?
Any support is GREATLY appreciated!