[R] Changing some values within a variable
Toni Pitcher
toni.pitcher at otago.ac.nz
Thu Jul 22 23:43:55 CEST 2010
Hi
I'm new to R and would like some help with a couple of problems. I
suspect the solutions are quite simple.
I have a data.frame (data) with 40 variables and 5238 observations
created from ~150 text files using read.table.
I would like to change some of the entries within two different columns.
Firstly, in the Group column I have groups A and B, I would like to
select all As and change to C. I have tried the following;
data$Group = ifelse(data$Group == 'A', "C", data$Group)
data$Group <- as.factor(data$Group)
This works to some extent, all As have been changes to Cs, but the Bs
have also been changed, in this case to "2", instead of remaining as
their original values. How do I get the Bs to stay the same?
Second problems is similar;
I need to change some of the Subject IDs. The required format is 3
numbers followed by 3 letters (999LLL). Some of the IDs have format
999LLL-LL, Thus I need to delete the -LL from the IDs.
How do I generically specify "find 999LLL-LL and replace with 999LLL"?
Many thanks in advance
Toni
--
Toni Pitcher PhD
Dept. of Medicine
University of Otago, Christchurch
Van der Veer Institute for Parkinson's and Brain Research
66 Stewart St
Christchurch 8011
New Zealand
Phone: +64 3 378 6075 (internal extn 86075)
Email: toni.pitcher at otago.ac.nz
More information about the R-help
mailing list