my R code for partition produces object not found problem

Viewed 19

I get the object not found problem with the following code. Could you please suggest how I can fix the problem? I appreciate your kind help.

Code:

# import csv file into R
library(tidyverse)
setwd("F:\\")
labor.data <- read.csv("labor.csv")

exists('labor')
# convert categorical variables to factor data type


labor %>% 
  mutate(loss4_new = case_when(loss4 == 1 ~ "one",
                               loss4 == 0 ~ "zero",
                                TRUE ~ NA_real_)) %>% 
  mutate(divpos_new = case_when(divpos == 1 ~ "one",
                                divpos == 0 ~ "zero",
                               TRUE ~ NA_real_))
  
# partition data into training and test sets

install.packages("caret")
library(caret)
set.seed(1)
sample <- sample(c(TRUE, FALSE), nrow(labor), replace=TRUE, prob=c(0.7,0.3))
train  <- labor[sample, ]
test   <- labor[!sample, ]

Console:

# import csv file into R
library(tidyverse)
setwd("F:\\")
labor.data <- read.csv("labor.csv")

exists('labor')
#[1] FALSE

# convert categorical variables to factor data type
 
labor %>% 
  mutate(loss4_new = case_when(loss4 == 1 ~ "one",
                               loss4 == 0 ~ "zero",
                                TRUE ~ NA_real_)) %>% 
  mutate(divpos_new = case_when(divpos == 1 ~ "one",
                                divpos == 0 ~ "zero",
                                TRUE ~ NA_real_))



# partition data into training and test sets
install.packages("caret")

Error in install.packages : object 'labor' not found

library(caret)
set.seed(1)
sample <- sample(c(TRUE, FALSE), nrow(labor), replace=TRUE, prob=c(0.7,0.3))

Error in nrow(labor) : object 'labor' not found

0 Answers
Related