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. -- Morten Sickel Norwegian Radiation Protection Authority -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Could you give some details on what commands you tried, what you hoped they would do, and how they failed? -----Original Message----- From: owner-r-help at stat.math.ethz.ch [mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of Morten Sickel Sent: Monday, September 23, 2002 10:59 AM To: 'r-help' Subject: [R] Newbie: Subsets of data frame 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","Andoy",..: 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. -- Morten Sickel Norwegian Radiation Protection Authority -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "Morten" == Morten Sickel <Morten.Sickel at nrpa.no> >>>>> on Mon, 23 Sep 2002 16:58:43 +0200 writes:Morten> I feel a bit embarassed by this, but I have not Morten> managed to find out how: I have a data frame Morten> containing measurements over time for a number of Morten> different locations: >> str(milk) Morten> `data.frame': 845 obs. of 3 variables: Morten> $ date : num 1987 1987 1987 1987 1987 ... Morten> $ value : num 5 1 2 5 1 1 2 3 2 4 ... Morten> $ location: Factor w/ 36 levels "Alta","And?y",..: 1 1 1 1 1 1 1 1 1 1 ... Morten> I assume there is some simpe way of extracting Morten> subsets of the data frame for analysing the time Morten> series for just one of the location, but how? I have Morten> tried using various variants of extract, [] and Morten> subset, but obiously, I have missed something, for I Morten> have not managed to get out what I want. milkA <- milk[ milk$location == "Alta" , ] or a bit more robustly, milkA <- subset(milk, location == "Alta") -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._