Tuesday, April 13, 2021

Conditional statement and new variable creation in R

 # Load data

p <- read.csv(file.choose())


#create new data for trial

#create new data for trial

lw9=ifelse(p$LANE_WIDTH<9, 1,0)

lw10=ifelse(p$LANE_WIDTH>=10 & p$LANE_WIDTH<11, 1,0)

lw11=ifelse(p$LANE_WIDTH>=11 & p$LANE_WIDTH<12, 1,0)

lw12=ifelse(p$LANE_WIDTH>=12 & p$LANE_WIDTH<13, 1,0)

lw13=ifelse(p$LANE_WIDTH>=13 & p$LANE_WIDTH<14, 1,0)

lw14=ifelse(p$LANE_WIDTH>=14 & p$LANE_WIDTH<15, 1,0)

lw15=ifelse(p$LANE_WIDTH>=15 & p$LANE_WIDTH<16, 1,0)

lw16=ifelse(p$LANE_WIDTH>=16 & p$LANE_WIDTH<17, 1,0)

lw17=ifelse(p$LANE_WIDTH>=17 & p$LANE_WIDTH<18, 1,0)

lw18=ifelse(p$LANE_WIDTH>=18 & p$LANE_WIDTH<19, 1,0)

lw19=ifelse(p$LANE_WIDTH>=19 & p$LANE_WIDTH<20, 1,0)

lw20=ifelse(p$LANE_WIDTH>=20 & p$LANE_WIDTH<21, 1,0)

lw21=ifelse(p$LANE_WIDTH>=21 & p$LANE_WIDTH<22, 1,0)

lw22=ifelse(p$LANE_WIDTH>=22, 1,0)


#combined data frame

data=cbind(p, lw9, lw10, lw11, lw12, lw13, lw14, lw15, lw16, lw17, lw18, lw19, lw20, lw21, lw22)


#for letter data

#create new data for trial

female<- ifelse(data$Gender=="Female", 1,0)

male<- ifelse(data$Gender=="Male", 1,0)

describe(newdata$CO2)

#Data to word

#for letter data

#create new data for trial

gender<- ifelse(data$Gender==1, "Female", "Male")


0 comments:

Post a Comment