[R] Cutting vectors

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Apr 3 11:21:06 CEST 2000


"Patrik Waldmann" <Patrik.Waldmann at sysbot.lu.se> writes:

> What I would like to do is as follows: I have a factor ex. fact 1 1
> 1 1 1 2 2 2 3 3 3 3 4 4 4 4, Levels: 1 2 3 4 and a variable ex. var
> 11 12 13 14 15 21 22 23 31 32 33 34 41 42 43 44 I take a bootstrap
> sample from the levels ex. nlev 1 1 4 3 and would like to construct
> a new vector (variable) ex nvar that corresponds to the levels in
> nlev, nvar should then look like 11 12 13 14 15 11 12 13 14 15 41 42
> 43 44 31 32 33 34 the next step would be to construct a new factor
> that corresponds to the size of the groups of nvar ex. nfact 1 1 1 1
> 1 2 2 2 2 2 3 3 3 3 4 4 4 4

Something like this should do it:

nvar <- unlist(split(var,fact)[nlev])
nfact <- factor(rep(1:4,table(fact)[nlev]))

(except that using "var" as a variable name may not be too good an
idea)

-- 
   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