You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This exercise lets you experience the different behavior of different ways to handle data.
Run the following blocks of code separately. First run the baseR and discuss within your group what happens.
Analyze and evaluate different approaches.
# base Rbasecars<-mtcarsbasecars$eco<-FALSEbasecars[basecars$mpg>22,"eco"] <-TRUEbasecars
# data.table
library(data.table)
dtcars<- as.data.table(mtcars)
dtcars[, eco:= ifelse(mpg>22, TRUE, FALSE)]
dtcars# Bonus# change the function and explore the# effect of copy()dtcars_2<- as.data.table(mtcars)
f<-function(d){
d[, eco:= ifelse(mpg>22, TRUE, FALSE)]
message("Object modified in place")
}
f(dtcars_2)
dtcars_2
This exercise lets you experience the different behavior of different ways to handle data.
Run the following blocks of code separately. First run the baseR and discuss within your group what happens.
Analyze and evaluate different approaches.
The text was updated successfully, but these errors were encountered: