data spliiting in r: random forest moderl

Please help me on how i can solve this error, Im having a problem in runniong this code

sample = sample.split(data$num, SplitRatio = 0.65
train = subset(data, sample == True)
test = subset(data, sample == False)

And Im receiving the error message below:

sample = sample.split(data$num, SplitRatio = 0.65
+ train = subset(data, sample == True)
Error: unexpected symbol in:
"sample = sample.split(data$num, SplitRatio = 0.65
train"
> test = subset(data, sample == False)
Error in subset.default(data, sample == False) : object 'False' not found
>

I assume sample.split is from caTools package.
be advised that for assignment <- is preferred over =
also in R, the primitives for true and false are capitalised entrirely TRUE,FALSE and not True False
I also noticed the sample.split call did not have a closing bracket.

sample <- sample.split(data$num, SplitRatio = 0.65)
train <- subset(data, sample == TRUE)
test <- subset(data, sample == FALSE)

Thank you, however afrter the corrections the error messahe shown below is now appearing.

ERROR MESSAGE

sample <- sample.split(data$num, SplitRatio = 0.65)
Error in data$num : object of type 'closure' is not subsettable

train <- subset(data, sample == TRUE)
Error in sample == TRUE :
comparison (1) is possible only for atomic and list types
test <- subset(data, sample == FALSE)
Error in sample == FALSE :
comparison (1) is possible only for atomic and list types

what is data ? i assumed it was a standard data.frame

The png shows how my .csv data frame.

THE WHOLE CODE I USE IS THIS ONE:

getwd()
setwd("C:/Users/Lucas M/Desktop")
Billy =read.csv("Billy.csv")
attach(Billy)
head(Billy)
names(Billy)<- c ("Village", "Time.resident.(yrs)", "Distance.to.pa.(km)", "Full.perimeter.fence", "Perimeter.ht.(m)", "Corral.distance.(m)", "Corral.ht.(m)", "Corral.area.(m²)", "Corral.strength.(1-5)", "Wooden.poles", "Metal.poles", "Horizontal.poles", "Metal.wiring", "Brash", "Cattle.lion.corral.attacks" )
sapply(Billy,class)
head(Billy)
Billy<- transform(Billy, Village= as.factor(Village))
sapply(Billy,class)
Billy<- transform(Billy, Full.perimeter.fence= as.factor(Full.perimeter.fence))
Billy<- transform(Billy, Wooden.poles= as.factor(Wooden.poles))
Billy<- transform(Billy, Metal.poles= as.factor(Metal.poles))
Billy<- transform(Billy, Horizontal.poles= as.factor(Horizontal.poles))
Billy<- transform(Billy, Metal.wiring= as.factor(Metal.wiring))
Billy<- transform(Billy, Brash= as.factor(Brash))
Billy<- transform(Billy, Cattle.lion.corral.attacks= as.factor(Cattle.lion.corral.attacks))
Billy<- transform(Billy, Time.resident..yrs.= as.numeric(Time.resident..yrs.))
sapply(Billy,class)
summary(Billy)
sample <- sample.split(data$num, SplitRatio = 0.65
train <- subset(data, sample == TRUE)
test <- subset(data, sample == FALSE)

THE PROBLEM IS ON RUNNING THIS CODE

sample <- sample.split(data$num, SplitRatio = 0.65
train <- subset(data, sample == TRUE)
test <- subset(data, sample == FALSE)

THE ERROR IS THIS

sample <- sample.split(data$num, SplitRatio = 0.65

  • train <- subset(data, sample == TRUE)
    Error: unexpected symbol in:
    "sample <- sample.split(data$num, SplitRatio = 0.65
    train"

test <- subset(data, sample == FALSE)
Error in sample == FALSE :
comparison (1) is possible only for atomic and list types

I think you are naively using the symbol data, where you set up a process that it would make sense to use Billy in its place.

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