r - 努力使用 Dplyr 进行变异
问题描述
我对 R 还是很陌生,在尝试获取平均值时遇到了以下错误:
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, ...)
我已经对在 Internet 上找到的一些代码进行了逆向工程,但我看不出他们的代码和我的代码之间的区别 - 请有人帮助并指导我做错了什么?
我采取的步骤如下:将数据拆分为 3 个元素:
- 在线是与在线体验相关的标准
- 机场是与飞行前经历的因素有关的标准
- 机上是与机上体验相关的满意度标准
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))
解决方案
推荐阅读
- git - 我可以在不同计算机之间共享的文件夹中使用 git,还是应该将项目克隆到不同的文件夹中?
- reactjs - 如何使用 ESLint 检查 React/Typescript 项目中的 prop 错误?
- python - Python数据未显示在html页面中
- assembly - 交叉组装臂组件时 _start 运行之前的 Segfault
- stackdriver - 如何创建基于百分位的指标图表?
- visual-studio-code - 无法从 VS Code 将 Altair 图表另存为 SVG
- mybatis - 如何在带有mybatis注解的if中枚举
- c# - 如何使用 System.Text.Json 将 Newtonsoft JToken 序列化为 JSON?
- java - 为什么我的 Play Framework 控制器不能识别我的 Singleton 类?
- architecture - 如何在数据库的一致性哈希中向环添加更多节点