Re: [R] changing a range of values

2009-01-17 Thread Dimitris Rizopoulos
try this: x - c(1,1,1,2,2,3,4,4,5,3.2,0.5) x[x = 1 x = 3] - 1 x I hope it helps. Best, Dimitris Jörg Groß wrote: Hi, If I have following vector; x - c(1,1,1,2,2,3,4,4,5) and I want to change values in the range of 1 to 3 into the value 1, how can I do that? I tried x[x ==

Re: [R] changing a range of values

2009-01-17 Thread jim holtman
Is this what you want: x - c(1,1,1,2,2,3,4,4,5) ifelse(x = 1 x = 3, 1, x) [1] 1 1 1 1 1 1 4 4 5 On Sat, Jan 17, 2009 at 12:03 PM, Jörg Groß jo...@licht-malerei.de wrote: Hi, If I have following vector; x - c(1,1,1,2,2,3,4,4,5) and I want to change values in the range of 1 to 3 into

Re: [R] changing a range of values

2009-01-17 Thread Gabor Grothendieck
If we know they are integer values only then this returns the desired vector replace(x, x %in% 1:3, 1) or this overwrites the input: x[x %in% 1:3] - 1 On Sat, Jan 17, 2009 at 12:03 PM, Jörg Groß jo...@licht-malerei.de wrote: Hi, If I have following vector; x - c(1,1,1,2,2,3,4,4,5) and

Re: [R] changing a range of values

2009-01-17 Thread Patrick Burns
The R Inferno, page 38. Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of The R Inferno and A Guide for the Unwilling S User) Jörg Groß wrote: Hi, If I have following vector; x - c(1,1,1,2,2,3,4,4,5) and I want to change values in the range of 1

Re: [R] changing a range of values

2009-01-17 Thread David Winsemius
x - c(1,1,1,2,2,3,4,4,5) x[x %in% 1:3] [1] 1 1 1 2 2 3 So ... x[x %in% 1:3] - 1 x [1] 1 1 1 1 1 1 4 4 5 On Jan 17, 2009, at 12:03 PM, Jörg Groß wrote: Hi, If I have following vector; x - c(1,1,1,2,2,3,4,4,5) and I want to change values in the range of 1 to 3 into the value 1, how