I'm trying reproduce code from someones study. So far I'm only trying to break down the function that reshapes the date into individual pieces to understand what it does exactly. When trying to create a new dataframe called 'datarule' based on the original 'data', i get "Error: object 'datarule' not found". What is going on in there? Probably a trivial thing, but would appreciate your help with this.
Here is my the R code:
data$test = as.logical(data$test) #convert 'test' col to boolean type True/False
max_learn_block <- max(data[!data$test, "block"])
data <- data %>%
mutate(block=ifelse(test, max_learn_block+1, block))
datarule <- data %>%
mutate(block=block+1) %>%
head(datarule)
Here is the original function code:
if (combine_test) {
max_learn_block <- max(data[!data$test, "block"])
data <- data %>%
mutate(block=ifelse(test, max_learn_block+1, block))
}
datarule <- data %>%
mutate(block=block+1) %>%
Thanks in advance!
The lines at the end of your code are
datarule <- data %>%
mutate(block=block+1) %>%
head(datarule)
Since the 2nd line ends with a pipe operator %>%
, the last line is taken to be part of the whole expression. But datarule
hasn't been created yet, so you get the error you saw.
To fix this, just leave off the %>%
pipe at the end of the 2nd line.