In Julia DataFrames, there is a useful feature for adding columns to empty dataframes.
df = DataFrame()
for i in 1:10
df[:, "var_$i"] = rand(100)
end
I have the need to do a similar operation in R. I have an 10 x 10 x 5 matrix. Along the third dimension I want to make a column in a tibble that is a vector of length 100. My current solution is
x = array(1, dim = c(10, 10, 5))
t = list()
for(i in 1:5){
n = paste0("var_", i)
t[[n]] = c(x[ , , i])
}
as_tibble(t)