首页 > 解决方案 > 在 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")

但结果我得到了一个空的数据框。

有人知道为什么子集在这种情况下不起作用吗?

标签: rvariablestestingstatisticssubset

解决方案


尝试这个:

df2 <- subset(df, df$Significance_ChangePoint_Q7min == "Significant" & 
                df$Significance_Qtest_Q7min == "No Independent")

带单&


推荐阅读