[R] replace numbers in a column conditional on their value
Richard.Cotton at hsl.gov.uk
Richard.Cotton at hsl.gov.uk
Wed Jan 16 18:01:26 CET 2008
> 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:20}}
More information about the R-help
mailing list