With the help of the following code I want to define an empty dataframe which is having 5 number of columns and then as you can see with the help of for loop I am assigning values to each and every column.
k = 1:5
dfk = data.frame(k1 = c(), k2 = c(), k3 = c(), k4 = c(), k5 = c())
for (j in 1:5){
for (i in 1:12){
dfk[j] = c(dfk[j], i+j)
}
plot(1:12, dfk[j])
}
I am getting the following error:
"Error in [.data.frame(dfk, j): undefined columns selected Traceback: 1. dfk[j] 2. [.data.frame(dfk, j) 3. stop("undefined columns selected")"