Error in rep(category, nrow(x)) : argument 'times' incorrect

hello R Community,
first of all, I would like to inform you that I am only a beginner in using RStudio software, basecally I am no a programmer and I am sorry if I didn't respect the instructions for posts. It is in fact my first time using this platforme.
I am trying to extract pixels values from a raster in order to perform a random forest classification afterwards.
So I am executing the code bellow but it seems that it has a mistake somewhere, would you please guide me on how to solve this issue.

>ex2<-ExtractByPoly(i,s,In.colName = "classT",Out.colName = "classT")
No. of bands - 9
No. of classes - 8
.....12% .....25% .....38% .....50% .....62% .....75% .....88% .....100% 
Extraction Completed
> dfAll = data.frame(matrix(vector(), nrow = 0, ncol = length(names(i)) + 1))   
> for (i in 1:length(unique(ex2[[responseCol]])))
+   category <- unique(ex2[[responseCol]])[i]
> categorymap <- ex2[ex2[[responseCol]] == category,]
> ex2 <- ex2[!unlist(lapply(ex2, is.null))]
> ex2_omit<-na.omit(ex2)
> ex2_omit <- lapply(ex2_omit, function(x){cbind(x, classT_fieldname = as.numeric(rep(category, nrow(x))))})
Error in rep(category, nrow(x)) : argument 'times' incorrect
Called from: cbind(x, classT_fieldname = as.numeric(rep(category, nrow(x))))
Browse[1]> Q

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.