Create a new variable based on the first 7 characters of existing variable

后端 未结 2 961
暖寄归人
暖寄归人 2020-12-06 15:08

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

相关标签:
2条回答
  • 2020-12-06 15:22

    You need to store the output of substr(variable2, 1, 7) into variable2. Currently you're printing only

    variable2<-mydata$variable
    variable2<-substr(variable2, 1, 7)
    
    0 讨论(0)
  • 2020-12-06 15:34

    You are passing wrong argument to substr

    Try

    variable2 <- substr(mydata$variable,1,7)
    
    0 讨论(0)
提交回复
热议问题