r - 在 R 中设置子集时出错 - 空数据帧
问题描述
我正在使用函数子集对数据框进行子集化,但没有成功:
> dput(df)
structure(list(Station = c("S09489500", "S09498500", "S09510200",
"S09494000", "S09497500", "S09492400", "S09504500", "S09503700"
), location = c("back", "back", "ahead", "ahead", "back", "ahead",
"ahead", "ahead"), length_years = c(36L, 75L, 33L, 34L, 75L,
35L, 49L, 34L), begin = c(1985, 1946, 1962, 1959, 1946, 1958,
1949, 1964), end = c(2020, 2020, 1994, 1992, 2020, 1992, 1997,
1997), Utest_Q7min = c(26.3618474823095, 119.756524166147, 12.749016687539,
20.3410125011518, 92.9397377831962, 19.8329511433346, 18.5949830661337,
34.4767872640756), Significance_Qtest_Q7min = c("No Independent",
"No Independent", "No Independent", "No Independent", "No Independent",
"No Independent", "No Independent", "No Independent"), PT_U = c(124,
567, 98, 181, 646, 158, 94, 238), ChangePoint_Q7min = c(26L,
19L, 9L, 17L, 29L, 23L, 30L, 16L), p_Q7min = c(0.292065629512458,
0.0219501976437697, 0.42182506012988, 0.0155276557662876, 0.00571923921900464,
0.0669830682326448, 1.28599300599023, 0.000449734648357696),
Significance_ChangePoint_Q7min = c("No significant", "Significant",
"No significant", "Significant", "Significant", "No significant",
"No significant", "Significant"), Man_Kendall = c("category 2",
"category 1", "category 1", "category 3", "category 1", "category 3",
"category 1", "category 3")), class = "data.frame", row.names = c(NA,
-8L))
我正在使用以下代码进行子集化:
df2 <- subset(df,df$Significance_ChangePoint_Q7min=="Significant" && df$Significance_Qtest_Q7min == "No Independent")
但结果我得到了一个空的数据框。
有人知道为什么子集在这种情况下不起作用吗?
解决方案
尝试这个:
df2 <- subset(df, df$Significance_ChangePoint_Q7min == "Significant" &
df$Significance_Qtest_Q7min == "No Independent")
带单&
推荐阅读
- javascript - localStorage 在 react js chrome 中不起作用
- python - 对本地文件夹中的所有文件重复 BeautifulSoup 抓取
- ethereum - 警告:不推荐使用从地址类型继承的合约成员“余额”。坚固性
- c# - 对有关初始化变量的课程说明感到困惑
- machine-learning - 数据科学:当 csv 文件有数千列时如何处理和清理数据
- pandas - lightgbm 是否按顺序返回预测?
- javascript - CKEDITOR 没有第二次初始化
- vb.net - 在 Visual Studio 中突出显示组合框/文本框时如何更改标签的颜色?
- typescript - 打字稿编译器忽略输出目录
- angular - 我无法提交我的表格