Trying to figure out this problem with some survey data. The responses are in multiple languages but always start with a number. Example: “1-Agree” or “1-Acceurdo.” I am trying to isolate just the number so everything after the numerical correspondent gets deleted.
Simple enough, but where I’m getting tripped up is how to do it across a multitude of variables. Luckily, all variables of interest start with “pre” or “post” so I’m seeing if maybe there’s a way to effectively loop through all these variables to isolate the number?
Additionally, there are certain questions that allow the respondent to select multiple values so it can’t just be “delete everything after 1st character.” One solution could be after to delimiter the data by comma?
Code for delimiting:
df$Pre3<-(do.call(“rbind”, strsplit(as.character(df$Pre_3), “,”, fixed = TRUE)))
Pre_3=”1-Doctor, 2-Nurse, 6-Hospital”
would turn into
Pre3[,1]=”1-Doctor” : Pre3[,2] =”2-Nurse” : Pre3[,3]= “6-Hospital”