I\'ve been struggling to create a new variable which contains only the first seven characters of an existing variable. Sorry if this if obvious but I\'ve struggled to find a
You need to store the output of substr(variable2, 1, 7) into variable2. Currently you're printing only
substr(variable2, 1, 7)
variable2
variable2<-mydata$variable variable2<-substr(variable2, 1, 7)
You are passing wrong argument to substr
substr
Try
variable2 <- substr(mydata$variable,1,7)