'How to find average of column when certain condition is met

I am new to R and am working with a data set with multiple columns but the ones I’m working with are “member_casual” and one that I made with

trip_data <- trip_data %>% 
  mutate(trip_duration = (ended_at - started_at))

trip_data <- trip_data %>% 
  mutate(trip_duration_min = (trip_duration/60))

I converted them from diff time to numeric

trip_data$trip_duration_min <- as.numeric(as.character(trip_data$trip_duration_min))

But i am trying to find the average trip_duration_min when for both members and casuals I tried this

trip_data %>% 
  select(trip_data, member_casual)
  filter(member_casual = 'member') %>% 
  summarize(mean = mean(trip_duration_min)

When I run

sapply(trip_data, class) 

it says it numeric but I get an error saying “must subset columns with valid subscript vector. has the wrong type ‘data.frame<“ I am stuck and any help would be appreciated

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source