'paste function to add data to dataframe in R
I am working on a ShinyApp which allows users to dynamically add columns to a dataframe based on their input. If users make two inputs, then I want to add two additional columns to the dataframe. Depending on the number of inputs a user made, the name of the input function in the ShinyApp changes (if one input, the name is input$textin1; if two inputs the name is input$textin2).
That's what I have so far to produce the dataframe:
data <- data.frame(test=NA)
for(i in 1:n){
new <- get(paste0("input$textin", n))
data[ , ncol(data) + 1] <- new
colnames(data)[ncol(data)] <- paste0("new", i)
}
data
However, the paste argument does not work.
What can I do to dynamically add data that is stored inside input$textin[number]?
(input$textin[number] actually looks like this: input$textin1 if one input was made or input$textin3 if three inputs were made.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
