0

I am still pretty new to R and I have encountered the following error when trying to get the average values:

Error: Problem with `mutate()` input `inflight_exp`. x error in evaluating the argument 'x' in selecting a method for function 'rowMeans': unused argument (starts_with("Inflight")) i Input `inflight_exp` is `rowMeans(fal1 %>% select(starts_with("Inflight")))`. Backtrace: 9. dplyr::mutate(...) 11. dplyr:::mutate_cols(.data, ...)

I have reverse engineered some code I found on the Internet and I could not see the difference between their code and mine - please could someone assist and guide me what I am doing wrong?

Steps I took are as follows: Split the data in to 3 Elements:

  1. Online is criteria relating to online experiences
  2. Airport is criteria relating to factors experienced before the flight
  3. Inflight is the satisfaction criteria relating to inflight experience
fal1 = rename(fal, Inflight1 = seat_comfort, 
    Airport1 = departure_arrival_time_convenient,
    Inflight2 = food_drink, 
    Airport2 = gate_location,
    Inflight3 = inflightwifi_service,
    Inflight4 = inflight_entertainment,
    Online1 = online_support,
    Online2 = ease_of_onlinebooking,
    Inflight5 = onboard_service,
    Inflight6 = leg_room_service,
    Airport3 = baggage_handling,
    Airport4 = checkin_service,
    Inflight7 = cleanliness,
    Online3 = online_boarding)
fal1 = fal1 %>% 
    mutate(inflight_exp = rowMeans(fal1 %>% select(starts_with("Inflight"))),
        airport_exp = rowMeans(fal1 %>% select(starts_with("Airport"))),
        online_exp = rowMeans(fal1 %>% select(starts_with("Online"))),
        male = ifelse(gender == 1,0,1))
Phil
  • 7,287
  • 3
  • 36
  • 66
Gordonmc
  • 1
  • 3
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What version of `dplyr` are you using? – MrFlick Aug 04 '20 at 05:14
  • 2
    Most probably you have `MASS` package loaded which is masking `dplyr::select`. Restart R and load only `dplyr` or use `dplyr::select` everywhere. – Ronak Shah Aug 04 '20 at 05:14
  • Thanks @RonakShah - Your advise solved the issue as soon as I restarted and didn't load MASS the code ran – Gordonmc Aug 04 '20 at 07:31
  • @MrFlick thank you for your comment i tried to create a simple example but even struggled with that - and i am using version 1.0.0 dplyr – Gordonmc Aug 04 '20 at 07:33

0 Answers0