Dear all,
I need to clean up one variables in a dataset.
e.g. lets say the dataset is "trial", the variable for cleaning up is "V1"
>trial$V1
[1] 0(a=1)   0(b=1)  0.133(b=1)   0.555(a=1)  >5.32(a=1)
what i need to do is to remove the text (a=1) and (b=1) and the ">" in the
V1, and then convert to a numeric variable, and als I am aslo requested that
when the value has a=1, the value needs to be divided by 5.
what I did is:
trialchara<-as.character(trial$V1)
trialnum<-gsub("(a=1)|(b=1)|>","",trialchara)
the result is
[1] "0 ()" "0 ()" "0.133 ()" "0.555 ()" "5.32 ()"
How can I get rid of the () symbol?
How can I do this part "when the value has a=1, the value needs to be
divided by 5." ?
Can anyone please give me some hints here?
Thanks a lot.
John

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to