Apostolos
Apostolos

Reputation: 598

apply on character vector

I want to produce a table from the elements of a list:

# The outcome must be something like that
1 = yes
2 = no
3 = non available

The code I wrote is as follows:

# 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

but there's seems that I am doing it wrong. Could someone help me ?

Upvotes: 0

Views: 679

Answers (1)

Apostolos
Apostolos

Reputation: 598

According to Pierre Lafortune this is one solution:

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

Upvotes: 1

Related Questions