[R] apply'ing cut to a data.set column

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Jun 5 16:19:32 CEST 2000


Massimo Santini <santini at dsi.unimi.it> writes:

> Hi all,
> 	there is probably something I'm still missing about how R
> manipulates multivariate data. I have a dataset in which, for various 
> tuples of a set of 4 parameters, a value of interest is stored:
> 
> 	p1   p2   p3   p4     v
>         0    0    0    0      0.2342
>         0    1    1    0      0.6124
>         ....
> 	0    0    1    1      0.1234
> 
> What I would like to do is to "cut" the "v" column of the dataset, let say
> with two breaks: (0,.5] (.5,1], to obtain something like
> 
>         p1   p2   p3   p4     v
>         0    0    0    0      (0,.5]
>         0    1    1    0      (.5,1]
>         ....
>         0    0    1    1      (0,.5]
> 
> I now how to do it on data$v, using cut, but I can't see a
> simple/straightforward way to do it on all the dataset, I'm confused about
> tapply, sapply, lapply and firends....

Is what you are trying to do as simple as

data$v <- cut(data$v,c(0,.5,1))

??

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list