Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.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_Subset - Fatal编程技术网

正在尝试在R中设置子数据帧

正在尝试在R中设置子数据帧,r,subset,R,Subset,我试图通过比较两列中的值来对dataframe进行子集设置。我用的是线下的 open <- open[open$AssignedGroup==open$Assigned.Group, ] 我插入了dataframe的结构以供参考 Num AssignedGroup Priority Assigned.Group 1 ABC DE Demo Integration E2E test 2 Medium ABC DE Demo Integration E2E test 2 1

我试图通过比较两列中的值来对dataframe进行子集设置。我用的是线下的

open <- open[open$AssignedGroup==open$Assigned.Group, ]
我插入了dataframe的结构以供参考

Num AssignedGroup   Priority    Assigned.Group
1   ABC DE Demo Integration E2E test 2  Medium  ABC DE Demo Integration E2E test 2
1   ABC DE Demo Integration E2E test 2  Medium  Group 1
1   ABC DE Demo Integration E2E test 2  Medium  Group 2
2   ABC DE Demo Integration E2E test 2  High    ABC DE Demo Integration E2E test 2
2   ABC DE Demo Integration E2E test 2  High    Group 1
2   ABC DE Demo Integration E2E test 2  High    Group 2
3   ABC DE Demo Integration E2E test 2  Low ABC DE Demo Integration E2E test 2
3   ABC DE Demo Integration E2E test 2  Low Group 1
3   ABC DE Demo Integration E2E test 2  Low Group 2
4   ABC DE Demo Integration E2E test 2  Low ABC DE Demo Integration E2E test 2
'data.frame':   82710 obs. of  4 variables:
 $ Num           : chr  "INC0615378" "INC0615378" "INC0615378" "INC0615495" ...
 $ AssignedGroup : chr  "ABC DE Demo Integration E2E test 2" "ABC DE Demo Integration E2E test 2" "ABC DE Demo Integration E2E test 2" "ABC DE Demo Integration E2E test 2" ...
 $ Priority      : chr  "Medium" "Medium" "Medium" "Medium" ...
 $ Assigned.Group: chr  "ABC DE Demo Integration E2E test 2" "GROUP 1" "Group 2" "ABC DE Demo Integration E2E test 2" ...
这对我很有用:

 Num<-c(1,1,1,2,2,2,3,3,3,4)
 AssignedGroup<-rep("ABC DE Demo Integration E2E test 2",10)
 Assigned.Group<-c("ABC DE Demo Integration E2E test 2","Group 1",
 "Group 2","ABC DE    Demo Integration E2E test 2","Group 1",
 "Group 2","ABC DE Demo Integration E2E test 2","Group 1",
 "Group 2","ABC DE Demo Integration E2E test 2")
 Priority<-c(rep("Medium",3),rep("High",3),rep("Low",4))
 df<- as.data.frame(cbind(Num,AssignedGroup,Priority,Assigned.Group))
 library(data.table)
 dfSubset<-df[which(df$Assigned.Group %like% df$AssignedGroup), ]
 dfSubset
#   Num           AssignedGroup             Priority              Assigned.Group
 #1    1 ABC DE Demo Integration E2E test 2   Medium ABC DE Demo Integration E2E test 2
 #4    2 ABC DE Demo Integration E2E test 2     High ABC DE Demo Integration E2E test 2
 #7    3 ABC DE Demo Integration E2E test 2      Low ABC DE Demo Integration E2E test 2
 #10   4 ABC DE Demo Integration E2E test 2      Low ABC DE Demo Integration E2E test 2

n使用
deput(head(YourDataSet,10))
添加一个可复制的数据集。
试试这个open@salmanashkarara,我插入了数据框的前10行作为参考。我想排除“AssignedGroup”和“Assigned.Group”没有相同的行values@shirin,我尝试了您的建议,得到了下面的警告,它在数据帧中返回0行“警告消息:在grepl(模式,向量):参数'pattern'的长度大于1,并且只使用第一个元素”我要求您添加
dput
结果。现在,我需要有
str(dt)
以及我在上面尝试过的它也对我有效,实际上之前它工作得很好,现在当有大量数据时它失败了,不理解问题我很糟糕,我发现问题在Assigned.Group列中“Demo”“Integration”之间有额外的空间,在实际的数据帧中,这就是为什么它不是子设置,真的很抱歉trouble@user3734568太好了,请你把这个标记为正确答案,然后谢谢