Re: [R] Class attributes

2009-12-04 Thread David Winsemius
On Dec 4, 2009, at 11:55 AM, Allen L wrote: Dear R forum, I want to replace all the elements in a data frame (dd) which match the character "x" with "0". What's the most elegant way of doing this (there must be an easy way which I've missed)? I settled on the following loop: for(i in 5:

Re: [R] Class attributes

2009-12-04 Thread jim holtman
Here a way of doing it: for (i in 5:12){ # convert to character so you can substitute 'x' a <- as.character(dd[,i]) a[a == 'x'] <- '0' replace with zero dd[,i] <- as.numeric(a) } On Fri, Dec 4, 2009 at 11:55 AM, Allen L wrote: > > Dear R forum, > I want to replace all the eleme

[R] Class attributes

2009-12-04 Thread Allen L
Dear R forum, I want to replace all the elements in a data frame (dd) which match the character "x" with "0". What's the most elegant way of doing this (there must be an easy way which I've missed)? I settled on the following loop: >for(i in 5:12){# These are the column of dd I am