我有一个数据数组,我试图仅对OR和WA状态的数据进行子集化。我正在尝试使用STATE行,并选择任何一个缩写OR和WA。当我运行脚本时,我得到了
redirect_back(fallback_location: root_path)
这是我正在使用的数据:
Error in dat_trans[dat_trans, "STATE" == "OR", ] :
incorrect number of dimensions
然后这是我尝试使用的子集数据的脚本
dat_trans <- structure(c(
"10263500", " 59.46390", "34.42083", "-117.8395", "CA", "old", NA,
"10281800", " 31.38300", "36.77854", "-118.2645", "WA", "new", NA,
"14037500", " 18.23760", "44.34155", "-118.6566", "OR", "new", NA
), .Dim = c(7L, 249L), .Dimnames = list(c("STAT_ID",
"DRAIN_AREA", "LAT", "LON", "STATE", "STUDY", "HUC_BASIN"), NULL))
答案 0 :(得分:0)
您有两个错误:
dat_trans[dat_trans, "STATE" == "OR", ]
^^^^^^^^^ ^ ^
dat_trans[dat_trans...
,在索引中重复df名称是没有道理的。STATE
列,或更确切地说是dat_trans$STATE
解决方案:
dat_trans[dat_trans$STATE == "OR", ]
dat_trans[dat_trans$STATE == "OR", tt]
或者如果您使用dplyr / tidyverse:
dat_trans %>% filter(STATE == "OR")