Создайте новый фрейм данных (назовите его C1), который является копией Carseats.
Создать две индикаторные (фиктивные) переменные:
Bad_Shelf = 1, если ShelveLoc = «Bad», 0 в противном случае
Good_Shelf = 1, если ShelveLoc = «Good», 0 в противном случае
Код в R:
#Load the dataset carseats(in the ISLR Package) into R.Studio
library(ISLR) #load and attach the package
View(Carseats) #view the data
data("Carseats") #loads the data "Carseats"
str(Carseats) #compactly displays the internal structure of the object
#(A) Make a new dataframe (Call it C1) that is a copy of carseats
C1 <- data.frame(Carseats)
#(B) Create two indicator (dummy variables)
#(B.1) Bad_Shelf = 1 if ShelveLoc = "Bad", 0 otherwise
Bad_Shelf <- ifelse(ShelveLoc = "Bad", 1, 0)
Good_Shelf <- ifelse(ShelveLoc = "Good", 1, 0)
**Error in ifelse(ShelveLoc = Bad, 1, 0) :
unused argument (ShelveLoc = Bad)