【发布时间】:2020-07-31 22:54:04
【问题描述】:
我在 sampleList 元素中添加了星号和新的换行符,以创建项目符号列表格式:
sampleList <- list(1, 2, 3)
# Create bulleted list
createPoints = function(list) {
# Pre-allocate list
setList <- vector(mode = "list", length = length(list))
# Add elements to each line
for (i in seq_along(list)) {
line = sprintf("* %s \n", list[[i]])
setList[[i]] <- line
}
return(setList)
}
finalList = createPoints(sampleList)
输出:
[[1]]
[1] "* 1 \n"
[[2]]
[1] "* 2 \n"
[[3]]
[1] "* 3 \n"
如何打印项目符号子列表中的各个元素?
这不起作用:
- 项目符号 1
r finalList
我的输出带有额外的逗号,子列表没有项目符号:
-
项目符号 1
- 1
, * 2
, * 3
我希望它看起来像这样:
- 项目符号 1
- 1
- 2
- 3
【问题讨论】:
-
您可以安装
pander并使用它,即pander::pander(sampleList)
标签: r for-loop r-markdown pandoc word