Final_data<-TY2019_rides %>%
mutate(member_casual= Membership
,"Subscriber"= member
, "Customer" = casual )
error: Problem with mutate()
column member_casual
.
Can anyone explain why this code is not working in my Rstudio?? Am I entering something wrong?
Please provide a reproducible example:
FAQ: What's a reproducible example (reprex
) and how do I create one?
If I had to totally guess, I assume that you don't have a column in your data called "Membership", but it is impossible to tell without seeing your data and code!
Further, one wouldn't use quotations within the left hand side of dplyr::mutate()
- I'm not sure what the third and fourth lines of your code are trying to achieve.
member_casual = c("Subscriber",
"Subscriber", "Subscriber", "Subscriber", "Subscriber", "Subscriber",
"Subscriber", "Customer", "Customer", "Customer", "Customer",
the objective is for me to make change the name of the column and the variables in the rows. I was hoping to accomplish this by using the following function:
Final_data<-TY2019_rides %>%
mutate(member_casual= Membership
,"Subscriber"= member
, "Customer" = casual )
Thanks in advance for your replies
But what does TY2019_rides
look like?
Anyway, I think you want something like case_when:
Is this what you're looking for?
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
df = tibble(member_casual = c("Subscriber",
"Subscriber", "Subscriber", "Subscriber", "Subscriber", "Subscriber",
"Subscriber", "Customer", "Customer", "Customer", "Customer"))
df
#> # A tibble: 11 x 1
#> member_casual
#> <chr>
#> 1 Subscriber
#> 2 Subscriber
#> 3 Subscriber
#> 4 Subscriber
#> 5 Subscriber
#> 6 Subscriber
#> 7 Subscriber
#> 8 Customer
#> 9 Customer
#> 10 Customer
#> 11 Customer
df %>%
rename(Membership = member_casual) %>%
mutate(Membership = case_when(
Membership == "Subscriber" ~ "member",
Membership == "Customer" ~ "casuaL"
))
#> # A tibble: 11 x 1
#> Membership
#> <chr>
#> 1 member
#> 2 member
#> 3 member
#> 4 member
#> 5 member
#> 6 member
#> 7 member
#> 8 casuaL
#> 9 casuaL
#> 10 casuaL
#> 11 casuaL
Created on 2021-12-28 by the reprex package (v2.0.1)
yes. this is very helpful
additionally this is the reprex requested
Thanks again
all_trips <- all_trips %>% mutate(member_casual = recode(member_casual,
Subscriber = "member", Customer = "casual"))
#> Error in all_trips %>% mutate(member_casual = recode(member_casual, Subscriber = "member", : could not find function "%>%"
Created on 2021-12-28 by the reprex package (v2.0.1)
system
Closed
January 18, 2022, 9:33pm
7
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.