Enter dataframe into R and assign it to the variable dat.

name<-c("Frank","Bob","Sally", "Susan","Joan", "Bill", "Richard","Jane", "Jill", "John")
Age<- c(34,28,19,28,30,47,24,34,32,64)
BMI<- c(24.2,18.3,15.4,22.7,29.2,32.4,21,40.4,24.8,34.4)
FactorA<- c(-1,-1,-1,-1,-1,1,1,1,1,1)
FactorB<- c(1,-1,1,-1,1,-1,1,-1,1,-1)
dat<-data.frame(name,Age,BMI,FactorA,FactorB)

Create a new column Factor AB that is the product of Factor A and Factor B.

FactorAB <- FactorA*FactorB
FactorAB
##  [1] -1  1 -1  1 -1 -1  1 -1  1 -1

Create a new column Factor C that looks as follows 

(-1,-1,1,1,-1,-1,1,1,-1,-1)

dat$FactorC<-c(-1,-1,1,1,-1,-1,1,1,-1,-1)

Creating a new column Factor ABC that is the product of Factor A, Factor B, and Factor C

dat$FactorABC <- dat$FactorA*dat$FactorB*dat$FactorC

Making all Factor columns recognized as factors in R 

dat$FactorA<-as.factor(dat$FactorA)
dat$FactorB<-as.factor(dat$FactorB)
dat$FactorC<-as.factor(dat$FactorC)
dat$FactorAB<-as.factor(dat$FactorAB)
dat$FactorABC<-as.factor(dat$FactorABC)

Additional column into the dataframe dat

dat$Smoking<-c("Yes","No","No", "Yes","Yes","No","Yes", "Yes","No","Yes")

Making sure it is recognized as a factor in R. 

dat$Smoking<-as.factor(dat$Smoking)

Replace the BMI of Richard with a NA

dat$BMI[dat$BMI == 21]<- NA

Creating a new column in dat with the logarithm of BMI

dat$LogBMI<- log(BMI)

Creating a new dataframe dat2 selecting only the columns from dat corresponding to logarithm of BMI, Factor A, Factor B, and Factor AB

dat2<-data.frame(dat$LogBMI, dat$FactorA,dat$FactorB, dat$FactorAB)

Creating a new dataframe dat3 selecting only the first 5 rows of dat2

dat3<-dat2[1:5,]