I want to create an empty dataframe and populate it row by row. The 1st column is latitude, the 2nd column is longitude, the 3rd is elevation, the next 12 columns represent values for 12 months. I don't know how to fill the last 12 columns at one time. There are many years, so each year takes one row in the dataframe. I think if this step has no problem, I will write it in a loop to fill all the rows. Thanks for your help.
df.year = data.frame()
for(i in 1:100){
df.year[i,1] = 20.15
df.year[i,2] = 108.10
df.year[i,3] = 5.5
df.year[i,] = cbind(df.year1[i,],c(7.97, 84.85, 0.00, 2.82, 0.00, 0.00, 24.49, 0.00, 0.00, 0.00, 0.00, 1.89))
}
Warning messages:
1: In data.frame(..., check.names = FALSE) :
row names were found from a short variable and have been discarded
2: In[<-.data.frame
(*tmp*
, i, , value = list(V1 = c(20.15, 20.15, :
replacement element 1 has 12 rows to replace 1 rows
...
or this line below
df.year[i,4:4+11] = cbind(df.year[i,],c(7.97, 84.85, 0.00, 2.82, 0.00, 0.00, 24.49, 0.00, 0.00, 0.00, 0.00, 1.89))
it gives the error
Error in
[<-.data.frame
(*tmp*
, i, 4:4 + 11, value = list(V1 = c(20.15, :
new columns would leave holes after existing columns
In addition: Warning message:
In data.frame(..., check.names = FALSE) :
row names were found from a short variable and have been discarded