[R] detecting measurement of specific id in column in R

Bert Gunter bgunter@4567 @ending from gm@il@com
Thu Nov 22 19:06:24 CET 2018


Jeff's advice is sound, but as I have a bit of time on my hand, I'll take a
guess at it. If it's wrong, then follow Jeff's advice so that we don't have
to continue to guess -- and do as he describes in any future posts, of
course. Note also that the mail server strips off attachments (except for a
few special types -- see the mailing list instructions for which), so you
need to follow the posting guide to post example data (see ?dput) .

It sounds to me as if your data are in a data frame, d, that looks like
this:

Sample_ID    IN       d13c        ppm_CO2    ppm_13CO2  .......
1                    v1        x1               y1             z1
1                    v2        x2               y2             z2
.      ...........      ..................................
.      ...................................................
1
2                   vm        xm               ym          zm
.
.
2                                     etc.
3
.
.

If so, then something like

nm <- c("d13c", "ppm_CO2", "ppm_13CO2")
by(d, d$Sample_ID, function(x){ x[, nm] - x[1, "IN"] }, simplify = FALSE )

would do what you seem to request. See ?by and associated links for details.

Again, if this is not what you want, do not ask me for further help. I'm
done guessing.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Nov 22, 2018 at 8:14 AM Romy Rehschuh via R-help <
r-help using r-project.org> wrote:

> Dear all,
>
> I hope this is the right way to ask questions.
> I have a problem with R regarding the detection of the measurement of a
> specific sample_id (see example file attached). I have to substract the
> "IN" values (means the air which goes into the chambers) from the values of
> "d13C", "ppm_CO2" and "ppm_13CO2" for every single chamber (=sample ID).
> The "IN" values have to be the ones which were measured* before *the
> measurements of the single chambers in time. I measured "IN" once and then
> up to 10 chambers in a row to safe time, then "IN" again, but it can
> change.
> Therefore, searching for the closest "IN" does not work.
>
> Do you have any suggestions? Would it be possible to write a loop for this?
> I would really much appreciate your help!
>
> Best, Vicci
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list