Re: [R] Clean up a complex variable

2009-05-23 Thread jim holtman
Here is one way of solving it: > x <- c('0(a=1)' ,'0(b=1)' ,'0.133(b=1)' ,'0.555(a=1)' ,'>5.32(a=1)') > # "(" and ")" have special meaning in regular expressions so they have to be escaped > (y <- as.numeric(gsub("\\(.*\\ )|>", "", x))) [1] 0.000 0.000 0.133 0.555 5.320 > # find "a=1" to div

Re: [R] Clean up a complex variable

2009-05-22 Thread andyer weng
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