On Fri, Jan 14, 2011 at 11:16 PM, Phil Spector
wrote:
> Is sapply really necessary here?
Apparently not, and it is certainly more cumbersome. Because data
frames can contain a mix of classes, I thought that round() did not
have a method for them (in retrospect that does not make much sense).
I h
Bill, Joshua, Phil
Thanks for the suggestions. Very much appreciated.
Kind regards
Pete
--
View this message in context:
http://r.789695.n4.nabble.com/Rounding-variables-in-a-data-frame-tp3218729p3219060.html
Sent from the R help mailing list archive at Nabble.com.
_
Is sapply really necessary here?
exc = !names(d) %in% "d3"
d[,exc] = round(d[,exc])
d
d1 d2 d3 d4
1 10 6 2.3749642 -4
2 11 6 -0.2081097 -2
3 10 4 1.2675955 -4
4 10 8 1.2468859 -2
5 10 6 2.7193027 -4
6 9 6 1.9195531 -5
7 9 6 2.8188036 -6
8 10 7 2.5755148 -4
9
Hi Pete,
Here is one option. The first part of sapply() just serves to get all
names of d except those you excluded in 'exc'. If you were including
fewer variables than you were excluding, just get rid of the logical !
operator.
d <- data.frame(d1 = rnorm(10, 10), d2 = rnorm(10, 6),
d3 = rnor
If you can specify the omitted columns as numbers there is a quick way to do
it. e.g.
> d
d1 d2d3d4
1 9.586524 4.833417 0.8142588 -3.237877
2 11.481521 6.536360 2.3361894 -4.042314
3 10.243192 5.506440 2.0443788 -3.478543
4 9.969548 6.159666 3.0449121 -4.827
5 matches
Mail list logo