我想要这样的输出,使用循环函数:
> stat-1, stat-2, stat-3, stat4, stat5.目前,这是我的代码:
x<-0;
while (x <= 10)
{
x <- x+1
z <- paste('stat-', x, collapse = "," )
print(z)
}但是我得到了这样的输出:
[1] "stat- 1"
[1] "stat- 2"
[1] "stat- 3"
[1] "stat- 4"
[1] "stat- 5" 如何获得单行输出?
发布于 2015-08-19 10:03:11
如果您想要几个字符串,也可以尝试:
x<-0;
z<-NULL;
while (x <= 10) {
x <- x+1
z <- c(z,paste('stat-', x, collapse = "," ))
}
print(z) 发布于 2015-08-19 10:08:24
您不需要for循环:
x <- 1:5
paste0("stat-", x, collapse = ", ")
# [1] "stat-1, stat-2, stat-3, stat-4, stat-5"如果你想要一个终点站“:
paste0(paste0("stat-", x, collapse = ", "), ".")
# [1] "stat-1, stat-2, stat-3, stat-4, stat-5."https://stackoverflow.com/questions/32092166
复制相似问题