我的数据如下
> cat(interim)
name:Huff,
data: [[15,0,15],#FF0000]
},{
name:santosh,
data: [[5,0,5],#FF0000]
},{
> cat(lastline)
name:sekhar,
data: [[7,0,7],0000CC]
我想要的最终输出如下。
name:Huff,
data: [[15,0,15],#FF0000]
},{
name:santosh,
data: [[5,0,5],#FF0000]
},{
name:sekhar,
data: [[7,0,7],0000CC]
我试过
paste( interim, lastline)
paste( interim, lastline, sep ="\n")
paste( interim, lastline, collapse = "\n")
paste( interim, lastline, sep ="\n", collapse = "\n")
但这些都不起作用。
我想知道这是因为我用来生成数据的序列。
(仅供参考,这是我如何获得临时数据集和最后一行数据集。)
JV <- data.frame('poster'= c('Huff','santosh', 'sekhar', 'sekhar'),
'nb' = c(15,5,7,7),
'sum' = c(0,0,0,0),
'color' = c('#FF0000','#FF0000','0000CC','0000CC'))
a <- paste(" name:", JV$poster[1:2], "," ,sep="")
b <- paste(" data: [[",JV$nb[1:2], "," , JV$sum[1:2], "," , JV$nb[1:2]*(JV$sum[1:2]+1) , "]", ",", JV$color[1:2],"]",sep="")
c <- " },{"
interim <- paste("\n",a,b,c,sep = "\n")
A <- paste(" name:", JV$poster[4], "," ,sep="")
B <- paste(" data: [[",JV$nb[4], "," , JV$sum[4], "," , JV$nb[4]*(JV$sum[4]+1) , "]", ",", JV$color[4],"]",sep="")
lastline <- paste("\n", A,B,sep = "\n")
任何建议都将非常感谢!
答案 0 :(得分:0)
我认为你没有问题:
> interim <- " name:Huff,
+ data: [[15,0,15],#FF0000]
+ },{
+
+ name:santosh,
+ data: [[5,0,5],#FF0000]
+ },{
+ "
> lastline <- " name:Huff,
+ data: [[15,0,15],#FF0000]
+ },{
+
+ name:santosh,
+ data: [[5,0,5],#FF0000]
+ },{
+
+ name:sekhar,
+ data: [[7,0,7],0000CC]
+ "
> result<-paste(interim, lastline)
> cat(result)
name:Huff,
data: [[15,0,15],#FF0000]
},{
name:santosh,
data: [[5,0,5],#FF0000]
},{
name:Huff,
data: [[15,0,15],#FF0000]
},{
name:santosh,
data: [[5,0,5],#FF0000]
},{
name:sekhar,
data: [[7,0,7],0000CC]
我知道当你要求R在提示中显示它时看起来很奇怪,但是当你使用它时,它会将\ n扩展为相应的字符。