Re: [R] Rounding variables in a data frame

2011-01-15 Thread Joshua Wiley
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

Re: [R] Rounding variables in a data frame

2011-01-15 Thread Pete B
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. _

Re: [R] Rounding variables in a data frame

2011-01-14 Thread Phil Spector
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

Re: [R] Rounding variables in a data frame

2011-01-14 Thread Joshua Wiley
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

Re: [R] Rounding variables in a data frame

2011-01-14 Thread Bill.Venables
__ From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Pete B [peter.breckn...@bp.com] Sent: 15 January 2011 14:53 To: r-help@r-project.org Subject: [R] Rounding variables in a data frame Hi All I am trying to use the round function on some columns of a dataframe while leavi

[R] Rounding variables in a data frame

2011-01-14 Thread Pete B
Hi All I am trying to use the round function on some columns of a dataframe while leaving others unchanged. I wish to specify those columns to leave unchanged. My attempt is below - here, I would like the column d3 to be left but columns d1, d2 and d4 to be rounded to 0 decimal places. I would w