Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.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_String_List - Fatal编程技术网

R-更改列表中字符的顺序

R-更改列表中字符的顺序,r,string,list,R,String,List,你好,我有这个名单 LIST<-list(list("DC,MD,MA,Washigton,Baltimore,Boston,France,Turkey,China"), list("DC,MD,Washington,Baltimore,France,Turkey"), list("DC,Washington,France,Turkey,China") 列表 编辑后: fun=function(string,NO){ lapply

你好,我有这个名单

    LIST<-list(list("DC,MD,MA,Washigton,Baltimore,Boston,France,Turkey,China"),
           list("DC,MD,Washington,Baltimore,France,Turkey"),
           list("DC,Washington,France,Turkey,China")
列表
编辑后:

 fun=function(string,NO){
  lapply(strsplit(string,","),function(x) 
    paste(c(by(x, c(s<-rep(1:NO,2),rep(0,length(x)-length(s)))
               ,paste0,collapse=",")),collapse=", "))
}
rapply(LIST,fun,how="list",NO=3)
fun=函数(字符串,否){
lapply(strsplit(字符串,“,”),函数(x)
粘贴(c)x,c(s
编辑后:

 fun=function(string,NO){
  lapply(strsplit(string,","),function(x) 
    paste(c(by(x, c(s<-rep(1:NO,2),rep(0,length(x)-length(s)))
               ,paste0,collapse=",")),collapse=", "))
}
rapply(LIST,fun,how="list",NO=3)
fun=函数(字符串,否){
lapply(strsplit(字符串,“,”),函数(x)

粘贴(c)(x,c(事实上,这一条更准确:列出你需要从中得到什么?你希望它如何安排?州应该离它的城市很近。对不起,我不知道美国的州和城市。你必须提供一种客观的方法,让人们把它翻译成代码。有多少个州有多少个城市?它们之间的关系就像我最初的帖子:如果x1,x2,x3是州,那么相应的城市是y1,y2,y3。可以有1到3个x和y,并且总是有尽可能多的x。实际上这一个更准确:列出你需要从中得到什么?你希望它如何安排?州应该离它的城市很近。对不起,我不知道美国的州和城市。你必须提供一个客观的方法或者把它转换成一个代码。有多少个州,有多少个城市?它们之间的关系就像我最初的帖子:如果x1,x2,x3是州,那么对应的城市是y1,y2,y3。可以有1到3个x和y,x和y总是一样多
 fun=function(string,NO){
  lapply(strsplit(string,","),function(x) 
    paste(c(by(x, c(s<-rep(1:NO,2),rep(0,length(x)-length(s)))
               ,paste0,collapse=",")),collapse=", "))
}
rapply(LIST,fun,how="list",NO=3)