r - 如何使用 check.names = false 但仍使用运算符 $
问题描述
我有包含括号和空格的列名。我可以使用check.names = False
.
但是,导入子集功能后不再起作用。我尝试了以下代码
test <- subset (df$"model code" == graph)
test <- subset (df, "model code" == graph)
test <- subset (df$'model code' == graph)
这是输出错误
subset.default(df$
model mode
== "graph") 中的错误:缺少参数 "subset",没有默认值
我如何使用 check.names 为假但仍使用运算符 $
这可行,但是使用以下代码在下游发生了一个新错误FUN(X[[i]], ...) 中的错误:对象'G'没有找到有关如何解决此问题的任何想法?
p2 <- ggplot(df, aes_string("Sample",i)) +
geom_boxplot(show.legend = F) +
geom_beeswarm(aes(color = Sample), size=2)
解决方案
您可以像这样使用反引号,并且您可能需要在因子水平周围加上引号。
subset(dat, `model code` == "graph")
# model code x
# 5 graph 1.8951935
# 7 graph -0.2572694
如果需要$
,最好使用括号进行子集化:
dat[dat$"model code" == "graph", ]
# model code x
# 5 graph 1.8951935
# 7 graph -0.2572694
推荐阅读
- c++ - Visual Studio中的c ++并行构建行为
- python - 在运行时检查复杂的变量参数
- python - 遍历行 pandas 数据框并添加值
- time-complexity - 为什么第二行执行 n (n + 1 / 2)
- node.js - 对 SCSS 使用 NPM,但脚本不会监视更改。它给了我一个错误
- java - Java中的Kotlin方法
- r - 安装 `qdap` - 无法安装
- java - 使用多个单词短语搜索时,Lucene 不起作用
- crystal-reports - 如何在 Crystal Reports 中更改多个列的顺序
- python - matplotlib 错误:从检查导入参数 ImportError:无法导入名称“参数”