Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 包含来自数组的值的子集数据帧_R - Fatal编程技术网

R 包含来自数组的值的子集数据帧

R 包含来自数组的值的子集数据帧,r,R,我有这个数据框: 'data.frame': 114034 obs. of 4 variables: $ Ore : chr "01 00" "01 01" "01 02" "01 03" ... $ SquareID: chr "10000" "10000" "10000" "10000" ... $ Intens : num 0.0118 0.00987 0.00538 0.01318 0.00273 ... $ Count : num 69 78 51

我有这个数据框:

'data.frame':   114034 obs. of  4 variables:
 $ Ore     : chr  "01 00" "01 01" "01 02" "01 03" ...
 $ SquareID: chr  "10000" "10000" "10000" "10000" ...
 $ Intens  : num  0.0118 0.00987 0.00538 0.01318 0.00273 ...
 $ Count   : num  69 78 51 86 35 ...

我需要对整个数据帧进行子集划分。数据帧的行,其中squared等于这些数组值

Df<-subset.data.frame(Df,Df$SquareID==c(4702,4703,4704,4705,5434,5435,4706,4707,4708,4709,4820,4939,4821,4822,5551,5057,4823,5058,4824,4825,5059,4826,5174,4940,4941,5175,4942,4943,5177,5178,4944,5060,4945,5061,4946,5062,5063,4728,5295,5296,5297,5180,5181,4845,4846,4847,4963,4964,5199,4353,5082,4355,4356,4585,9536,4586,4587,4470,4588,4471,4589,4472,4473,5412,5413,5414,9653,4590,4591,5530,5315,5316,5318)
Dfnrussell是对的。
假设你有一个数据帧

> df <- data.frame(SquareId = c("1","2","3","4"), Intens = c(15,30,45,60))
> df
  SquareId Intens
1        1     15
2        2     30
3        3     45
4        4     60
>测向
平方强度
1        1     15
2        2     30
3        3     45
4        4     60
您可以将其子集如下所示:

> df <- subset(df, SquareId %in% c("2","3"))
> df
  SquareId Intens
2        2     30
3        3     45
>测向
平方强度
2        2     30
3        3     45

问题在于行中的逻辑比较:

Df<-subset.data.frame(Df,Df$SquareID==c(4702,4....))

请参阅帮助文件
?“%in%”
。我需要对整个数据帧进行子集设置,我不需要作为resultRight的向量,
子集(Df,squared%在%c(…)中)
。您的
squared
列是
character
,因此您应该首先将其转换为
numeric
。请查看
1:2==1:3
中的警告。这和你得到的一样above@nrussel谢谢,如果你想回答的话就写下来。
 Df<-subset(Df,Df$SquareID %in% c(4702,4....))