r - R将相同的因子值视为不同的值
问题描述
我是 R 的新用户,正在尝试对我的一个专栏进行子集化。但是,某些值丢失/未子集到新子集。
我尝试了代码拼写的不同变体,但它似乎不起作用(即:)
df_Location = df[df$Location == "Samarinda" | df$Location == "Samarinda " df$Location == "Samarinda. " df$Location == " Samarinda",]
df_Location
summary(df)
df_Location = df[df$Location == "Samarinda",]
df_Location
summary(df)
df_Location = df[df$Location == "Samarinda",]
df_Location
summary(df)
这些代码只产生了 7 行的子集 --> 原始数据中应该有 37 行
当我使用 rPivotTable 时,这就是它所显示的内容(Samarinda 列出了两次,值分别为 30 和 7):
Samarinda 30
Samarinda 7
Totals 221
谁能建议如何解决这个问题?
非常感谢
解决方案
grepping 的替代方法可以通过 运行字符串trimws
,如下所示:
df_Location = df[trimws(df$Location) == "Samarinda",]
推荐阅读
- python - 如何将 CSS 文件链接到 Django 的 pdf.html 文件,修复 FileNotFoundError
- javascript - Vanilla JS如何更新本地存储数组中的值?
- java - Gradle 同步失败:不支持的方法:SyncIssue.getMultiLineMessage()。(安卓工作室)
- typescript - Typescript - 将两个动态处理的枚举合并为一个
- java - Tomcat 错误 - 状态码 404,资源不可用
- xml - Open XML 仍然是一回事吗
- android - Firebase 电话身份验证已启用,但应用程序一直说它已禁用;我能做些什么?
- r - 如何查看 R 中类方法的可用参数和文档?
- javascript - 如何从请求 API 获取响应数据 XML?
- jquery - 如何在 node-express 项目中包含引导程序