I am using a function to grab data from our organization server which then need to be stored in an empty data.frame
through a for loop
. The data is for March 01 to May 31 (92 days) for 130 different sites (130 columns for the sites while 1 column for the date).
tss <- as.data.frame(matrix(NA, 92,131))
The function itself works. The for loop also works for the first 14 stations but then it spit out the following error
> Error in `[<-.data.frame`(`*tmp*`, , i + 1, value = c(0, 0, 0, 0, 0,
> 0, : replacement has 90 rows, data has 92
The for loop that i am using to populate the empty matrix is as follow
for (i in 1:nlines) {
tss1 <- fromAquarius(id[i],Data[i],Stage[i])
tss[,i+1]<-tss1$Daily_sum
rm(tss1)
}
Is there a way to let the code run and fill in the matrix with available data and leaving the cell as NA if there is no data while moving forward? There could be another way to handle the error.