My overall goal is to classify an image using random forest. The dataframe contains training data; where 'landcover' contains the classes 0, 1 and 2. I am trying to reduce the number of classes by changing all the 2's to 0's, using the dplyr transmute() method. The whole code works except for the critical last line-- GP_training1 <- transmute(GP_data$landcover, landcover = ifelse(landcover==1,1,0))
. When I run this I get the error: no applicable method for 'mutate_' applied to an object of class "c('integer', 'numeric')". Any ideas why this may be? Relevant code is pasted below.
#import raster and shapefile; each color band is overlayed on top of
eachother w coordinate system underneath
GP_1_4 <- brick("Downloads/Landsat Mosaics/GP_1-4.tif")
names(GP_1_4) <- c("Red","Green","SWIR")
GP_1_4 <- subset(GP_1_4, order(c(3, 2, 1)))
plotRGB(GP_1_4,stretch="lin")
#import shapefile of training points
GP_training < readOGR("Downloads/GP_716_shapefile3/GP_716_training3.shp", layer="GP_716_training3")
list.files("GP_716_shapefile3")
#extract points from raster
dataSet <- as.data.frame(extract(GP_1_4, GP_training))
#and put in same dataframe as training data
GP_training$data = data.frame(GP_training$data, dataSet[match(rownames(GP_training$data), rownames(dataSet)),])
GP_training$data = GP_training$data[complete.cases(GP_training$data),]
#make a new dataframe, identical to GP_training, except the 2's are changed to 0's
GP_training1 <- GP_training
GP_data <- GP_training1$data
GP_training1 <- transmute(GP_data$landcover, landcover = ifelse(landcover==1,1,0))
NEW EDIT: Using the function isS4(), I've discovered that GP_training is an S4 object. Meanwhile, R documentation says that "All main verbs are S3 generics" for transmute(). I'm not very familiar with S3 and S4, but could this be where the error is happening?