Re: [R] replace numbers in a column conditional on their value

From: Jabez Wilson <jabezwuk_at_yahoo.co.uk>
Date: Thu, 17 Jan 2008 15:43:15 +0000 (GMT)


Splendid, thanks for your quick response.

Richard.Cotton_at_hsl.gov.uk wrote: > I have a data frame column in which I would like to replace some
> of the numbers dependent on their value.
>
> data frame = zz
>
> AveExpr t P.Value FC
> 7.481964 7.323950 1.778503e-04 2.218760
> 7.585783 12.233056 6.679776e-06 2.155867
> 6.953215 6.996525 2.353705e-04 1.685733
> 7.647513 8.099859 9.512639e-05 1.674742
> 7.285446 7.558675 1.463732e-04 1.584071
> 6.405605 3.344031 1.276812e-02 1.541569
>
> I would like to replace the values in column 'FC' which are >2
> with their squared value.
> If I do this, however, I get a warning but it does the sum correctly.
> Warning message:
> number of items to replace is not a multiple of replacement length
> in: zz[, 4][zz[, 4] > 2] <- zz[, 4]^2

Try
zz$FC[zz$FC > 2] <- (zz$FC[zz$FC > 2])^2

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION: This message contains privileged and confidential inform...{{dropped:27}}

R-help_at_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. Received on Thu 17 Jan 2008 - 15:56:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Jan 2008 - 16:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive