我想从列表元素中生成一个表:
# The outcome must be something like that
1 = yes
2 = no
3 = non available
我写的代码如下:
# Create the Label list
Labels <- vector(mode = "list")
Question <- seq(1, 3)
QuestionDescription <- c("yes", "no", "non available")
Labels[[length(Labels)+1]] <- cbind(Question, QuestionDescription)
names(Labels)[length(Labels)] <- "Question"
Labels
# Use the following function
fApply <- function(x, y)
{
paste(x, " = ", y, "\n", sep = "", collapse = "")
}
# Use the appropriate apply function
Outcome <- apply(Labels[[1]][, 1], Labels[[1]][, 2], fApply)
Outcome
但似乎我做错了。 有人能帮助我吗?
答案 0 :(得分:1)
根据Pierre Lafortune,这是一个解决方案:
cat(paste0("\n", paste(Question, QuestionDescription, sep=" = ")))