Hello,

Thank you very much for looking at this. I have a "seasonal" user for R. I
teach my undergrads and graduates students statistics using R and often find
myself trying to solve problems to process student collected data in an
efficient way.

In this case, I have a data.frame with multiple observations. These are gas
concentrations in a chamber and are used to measure into rates, usually (not
not always), four or five observations per chamber.

Data are from several sites and multiple dates. I'd like to run a regression
to calculate the rate of emissions, for each date and site.

The regression is using concentration ~ Sample_interval (which is in
seconds).

lm(Concentration ~ Sample_interval, data=df)

The data.frame looks something like this:

Date               Time                     Site
Sample_interval                Concentration
10/03/09          5:00                     Site 1
0                                       334
10/03/09          5:00                     Site 1
566                                   355
10/03/09          5:00                     Site 1
1005                                 367
10/03/09          5:00                     Site 1
1244                                 384
10/03/09          5:00                     Site 2
0                                       434
10/03/09          5:00                     Site 2
466                                   455
10/03/09          5:00                     Site 2
1005                                 437
10/03/09          5:00                     Site 2                 1349
                                474
10/12/09          5:00                     Site 1
0                                       354
10/12/09          5:00                     Site 1
506                                   359
10/12/09          5:00                     Site 1
1065                                 377
10/12/09          5:00                     Site 1
1184                                 394
10/12/09          5:00                     Site 2
0                                       424
10/12/09          5:00                     Site 2
396                                   495
10/12/09          5:00                     Site 2                 1022
                                497
10/12/09          5:00                     Site 2
1304                                 574

I tried this:

bylist.lm <- by(df, list(df$Date, df$Site),
      function(x) lm(Concentration~Sample_interval, data=x))

Then, I get a list of stuff...which seems hard very exact much...

I tried this...

rate <- (sapply(bylist.lm, coef)[2,])

and got, the rates, but I can't figure out how to line them up with the "by"
variables.

So... In a perfect world, I would like to get a data frame with the
intercept, slope, r.square, p.value for each date, site, so the question
involves extracting from a "by" class, and mode "list". Granted, I have been
confused for a few years on how to think about classes and modes...so some
insight there would also be quite appreciated...


-- 
Marc Los Huertos
Assistant Professor
Science and Environmental Policy
100 Campus Drive
Seaside CA, 93955

831-582-3209

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to