[英]R- rbind duplicated rows
I need to extract all numbers from a string and save them in one field as a list. 我需要从字符串中提取所有数字,并将它们保存在一个字段中作为列表。 My code is: 我的代码是:
library(stringr)
d<-data.frame(dir='a', x=1)
DIR<-"PJE INDEPENDENCIA 96 5"
X <- str_extract_all(DIR,"\\(?[0-9]+\\)?")[[1]]
d<-rbind(d, data.frame(dir=DIR , x=X))
But I get: 但是我得到:
> d
dir x
1 a 1
2 PJE INDEPENDENCIA 96 5 96
3 PJE INDEPENDENCIA 96 5 5
While I need to get: 虽然我需要获得:
dir x
1 a 1
2 PJE INDEPENDENCIA 96 5 96,5
I tried adding list, but didn't work. 我尝试添加列表,但是没有用。 How can I avoid rbind generating all possible combinations? 如何避免rbind生成所有可能的组合? Thanks 谢谢
您可以尝试d<-rbind(d, data.frame(dir=DIR , x=toString(X)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.