[R] Newbie: Subsets of data frame

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Sep 23 17:23:28 CEST 2002


Morten Sickel <Morten.Sickel at nrpa.no> writes:

> I feel a bit embarassed by this, but I have not managed to find out how:
> 
> I have a data frame containing measurements over time for a number of
> different locations:
> 
> > str(milk)
> `data.frame':   845 obs. of  3 variables:
>  $ date    : num  1987 1987 1987 1987 1987 ...
>  $ value   : num  5 1 2 5 1 1 2 3 2 4 ...
>  $ location: Factor w/ 36 levels "Alta","Andøy",..: 1 1 1 1 1 1 1 1 1 1 ...
> 
> I assume there is some simpe way of extracting subsets of the data frame for
> analysing the time series for just one of the location, but how? I have
> tried using various variants of extract, [] and subset, but obiously, I have
> missed something, for I have not managed to get out what I want. 

Did you try

subset(milk,location=="Andøy")

?


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