I have data in multiple vectors that I would like to convert to a data.frame with one ID column (vector name) and one data column (vector values). Here's a toy example:
data.1 <- c(1, 2)
data.2 <- c(10, 20, 30)
df <- bind_rows(data.frame(ID="data.1", value=data.1), data.frame(ID="data.2", value=data.2))
If I have another vector (or any other data structure) that contains the name of the variables as a character string, how can I elegantly shorten the code? One time I would need to retrieve the entry as a character string (for ID) and the other time as the variable name (for value).
studies <- c("data.1", "data.2")