[R] Pointer to covariates?

Göran Broström gb at stat.umu.se
Wed Feb 20 14:42:39 CET 2002


I have a dataframe 'dat' with one response and some covariates. Many 
observations  (rows), but only a few unique combinations of 
the covariates. Let's say that the response is in column 1, and 
the covariates in columns 2:k.

I want to do 

> covar <- unique.data.frame(dat[, 2:k])
> y <- dat[, 1]
> keys <- ??????

where 'keys' should be a vector of length length(y) and contain the
row numbers in 'covar', where the response will find its covariates.

Example:

> dat
  y x1 x2
1 1  1  0
2 2  0  1
3 3  1  0

> unique.data.frame(dat[, 2:3])
  x1 x2
1  1  0
2  0  1

> keys
1  1
2  2
3  1

But how do I get 'keys'?
-- 
 Göran Broström                      tel: +46 90 786 5223
 professor                           fax: +46 90 786 6614
 Department of Statistics            http://www.stat.umu.se/egna/gb/
 Umeå University
 SE-90187 Umeå, Sweden             e-mail: gb at stat.umu.se

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