[R-sig-Geo] Splitting polygon dataset

Bede-Fazekas Ákos b|@|ev||@t @end|ng |rom gm@||@com
Fri Aug 23 12:26:22 CEST 2019


Dear Enoch,

There is a typo in your code that causes the error: function c() is not 
equivalent of C().
Solution:
id <- sample(2, nrow(dfTrainshape), prob = c(0.7, 0.3), replace = TRUE)

HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences

2019.08.23. 12:17 keltezéssel, Enoch Gyamfi Ampadu írta:
> Dear List,
>
> Please I have been implementing Random Forest in R for the to classify
> forest cover. I am doing it for 4 main classes. I Have extracted the pixel
> values of the bands with that of the training polygons. In all I had 226
> observations and the 8 bands as the response variables.
>
> I tried to split it into 70% for training set and 30% for as testing set
> sing the codes below;
>
> #setting training and testing samples
> set.seed(999)
>
> id <- sample(2, nrow(dfTrainshape), prob = C(0.7, 0.3), replace = TRUE)
> dfTrainshape_train <- dfTrainshape[id==1,]
> dfTrainshape_test <- dfTrainshape[id==2,]
>
> I had the error below;
>
> set.seed(999)
>> id <- sample(2, nrow(dfTrainshape), prob = C(0.7, 0.3), replace = TRUE)
> Error in C(0.7, 0.3) : object not interpretable as a factor
>> dfTrainshape_train <- dfTrainshape[id==1,]
> Error in `[.data.frame`(dfTrainshape, id == 1, ) : object 'id' not found
>
> I will be glad to have some advice and probable some code to assist me.
>
> Secondly,
>
> Please I also want to create a separate testing polygons for the validation
> in ArcMap. I want to know how I will be able to use the 226 observations of
> the earlier set of polygons for the training and the new polygons for
> validation. I will be glad to have some codes which I can change to suite
> what I want to do.
>
> Hope to hear from you.
>
> Best regards,
>
> Enoch
>
>



More information about the R-sig-Geo mailing list