应用于字符向量

apply on character vector

我想从列表的元素中生成一个 table:

# 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

但是我好像做错了。 有人可以帮我吗?

根据Pierre Lafortune,这是一个解决方案:

cat(paste0("\n", paste(Question, QuestionDescription, sep=" = ")))