小编Lon*_*olf的帖子

正确使用%in%的正确方法

我是R的新手,并且编写了以下代码。但是,我相信可能会有更好的方法来实现以下代码:

在代码中,我多次复制并粘贴了一个代码,以从同一变量中滤除不同的观察结果。我尝试使用%notin%,但它似乎对我不起作用

select.other <- have_data[which(have_data$TOP_NM == 'Other'),names(have_data) %in% c("TOP_NM","SERIES_NM","SERIES_VAL","RANK")]
select.other <- select.other[which(select.other$SERIES_NM != 'Constant=1 in Q1'),names(select.other) %in% c("TOP_NM","SERIES_NM","SERIES_VAL","RANK")]
select.other <- select.other[which(select.other$SERIES_NM != 'Constant=1 in Q2'),names(select.other) %in% c("TOP_NM","SERIES_NM","SERIES_VAL","RANK")]
select.other <- select.other[which(select.other$SERIES_NM != 'Constant=1 in Q3'),names(select.other) %in% c("TOP_NM","SERIES_NM","SERIES_VAL","RANK")]
select.other <- select.other[which(select.other$SERIES_NM != 'Constant=1 in Q4'),names(select.other) %in% c("TOP_NM","SERIES_NM","SERIES_VAL","RANK")]
select.other <- select.other[which(select.other$SERIES_NM != 'Time: Quarterly'),names(select.other) %in% c("TOP_NM","SERIES_NM","SERIES_VAL","RANK")]
select.other <- select.other[which(select.other$SERIES_NM != 'Time: Quarterly Projected'),names(select.other) %in% c("TOP_NM","SERIES_NM","SERIES_VAL","RANK")]
select.other 
Run Code Online (Sandbox Code Playgroud)

希望有一种更简单的方法可以给我同样的结果。在此先感谢您的帮助和指导

r subset

4
推荐指数
1
解决办法
66
查看次数

标签 统计

r ×1

subset ×1