[R] Newbie question about data preparation

Dieter Menne dieter.menne at menne-biomed.de
Wed Nov 14 11:32:56 CET 2007


Heidemeier Dr, Joachim <joachim.heidemeier <at> uba.de> writes:

> 
...
> For the analyses of the data I want to group one column (like the
> classes in a histogram).
> So I'd like to add one column with the center of each group with width=2
> for an x value in the interval of the class.
> So the output should look like 
>   x	y	x-grouped
> 1.3	2.2	1
> 2.5	3.4	3
> 3.1	3.7	3	
> 8.2	9.5 	9
> 7.5	8.3	7
> What would be the R'ish idiom to do this operation?

df = data.frame(x=rnorm(10,10),y=rnorm(10,20))
df$xgrouped = (df$x+df$y) %/%2



More information about the R-help mailing list