Romy Rehschuh
2018-Nov-22 09:33 UTC
[R] detecting measurement of specific id in column in R
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
Jeff Newmiller
2018-Nov-22 16:53 UTC
[R] detecting measurement of specific id in column in R
You hope... but no... not really. You need to enhance your question with a (minimal) example of the data just after importing into R, and another example of what you think the result should look like. Also, you should provide your current best guess at what a calculation would include expressed in R to help clarify your description. In your case you might be able to separate your problem into "find a row number for the first reading" and then what calculations would make if you knew "n" was that row number... but those are guesses because I don't know what your data look like. A recommended technique to provide data is to use the dput function to format R data and paste it into your email... read more at [1][2][3]. [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example [2] http://adv-r.had.co.nz/Reproducibility.html [3] https://cran.r-project.org/web/packages/reprex/index.html (read the vignette) On November 22, 2018 1:33:39 AM PST, Romy Rehschuh via R-help <r-help at 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 at 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.-- Sent from my phone. Please excuse my brevity.
Rui Barradas
2018-Nov-22 16:53 UTC
[R] detecting measurement of specific id in column in R
Hello, No attachment arrived. R-help allows only a limited number of file types to be attached, if you file is a text file, change its extension to .txt an try again, please. Hope this helps, Rui Barradas ?s 09:33 de 22/11/2018, Romy Rehschuh via R-help escreveu:> 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 at 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. >
Romy Rehschuh
2018-Nov-22 17:42 UTC
[R] detecting measurement of specific id in column in R
Dear all, if the attachment didn?t arrive, maybe it works now. I would like to substract the "IN" values (= the air which goes into the chambers) for "d13C", "ppm_CO2" and "ppm_13CO2" from the "d13C", "ppm_CO2" and "ppm_13CO2" for every single chamber. I need to substract the "IN" values which were measured *before* the chamber. So the calculation would look like df$d13C [chambers] - df$d13C [IN] df$ppm_CO2 [chambers] - df$ppm_13CO2 [IN] df$ppm_13CO2 [chambers] - df$ ppm_13CO2 [IN] --> for chamber 101-111 this should be the first "IN" (No 1) --> for chamber 1-11 this should be the second "IN" (No 12) ...and so on I tried sth. like which(abs(date-x) == min(abs(date-x), but it just gives me the closest "IN" in time and not the "IN" before. I would appreciate any help! Thank you so much, Vicci Am Do., 22. Nov. 2018 um 17:53 Uhr schrieb Rui Barradas < ruipbarradas at sapo.pt>:> Hello, > > No attachment arrived. > R-help allows only a limited number of file types to be attached, if you > file is a text file, change its extension to .txt an try again, please. > > Hope this helps, > > Rui Barradas > > ?s 09:33 de 22/11/2018, Romy Rehschuh via R-help escreveu: > > 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 at 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. > > >-------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: Example.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20181122/926dbcef/attachment.txt>
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 at 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 at 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]]
No attached file. R-help is very fussy about what kind of file it will accept, A txt or pdf is the best bet. On the other hand it usually is best to include any code and sample data in the actual e-mail.? Use the function dput() as the best way to supply data. On Thursday, November 22, 2018, 11:15:00 a.m. EST, Romy Rehschuh via R-help <r-help at 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 at 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]]