Brian Leo
2017-May-09 04:33 UTC
[R] Extract cells and their adjacent cells that may appear anywhere in a dataframe.
Hello, I have a dataframe that contains information about vegetation cover and percent coverage, collected using a quadrat. The dataframe is set up so that each row represents a single quadrat. If there are multiple species within one quadrat, they are all listed within the same row with respective % coverage always following in next column. Here is an example, species are represented as 4 letter codes: Quadrat_# Date Species_1 Species_2 covrage2 Species_3 covrage3 1 5/2/2017 unk1 2 bial 6 stgu 95 2 5/2/2017 bope 75 stja 4 ficy 9 3 5/2/2017 bope 100 stja 5 4 5/2/2017 stgu 87 stja 6 bope 20 5 5/2/2017 bg 13 stja 2 ficy 10 6 5/2/2017 bope 8 sirh 3 stgu 2 The problem is that the species were not recorded in any particular order, and not all species occur in every quadrat. There can also be any number of species per quadrat. I need to be able to extract each species AND it?s respective coverage, and place them in into another dataframe for further analysis So the result for ?bope? from above example data would look like this: Quadrat# % coverage bope 1 0 2 75 3 100 4 20 5 0 6 8 Any help greatly appreciated. Brian [[alternative HTML version deleted]]
Jeff Newmiller
2017-May-09 05:17 UTC
[R] Extract cells and their adjacent cells that may appear anywhere in a dataframe.
Please don't post in HTML... what YOU see is almost never what WE see (look below for something like what I saw). Read the Posting Guide for more help on how to use the list, including the recommendation to formulate your question as a minimal R example (runnable code). See for example [1] and/or [2]. From your description the solution will either be a reshape-operation or a line-by-line parsing of the data, depending how the input data are laid out in the file, which is not clear in the mess below. [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example [2] http://adv-r.had.co.nz/Reproducibility.html -- Sent from my phone. Please excuse my brevity. On May 8, 2017 9:33:25 PM PDT, Brian Leo <leobriant at gmail.com> wrote:>Hello, > >I have a dataframe that contains information about vegetation cover and >percent coverage, collected using a quadrat. The dataframe is set up >so >that each row represents a single quadrat. If there are multiple >species >within one quadrat, they are all listed within the same row with >respective >% coverage always following in next column. Here is an example, >species >are represented as 4 letter codes: > >Quadrat_# > >Date > >Species_1 > >Species_2 > >covrage2 > >Species_3 > >covrage3 > >1 > >5/2/2017 > >unk1 > >2 > >bial > >6 > >stgu > >95 > >2 > >5/2/2017 > >bope > >75 > >stja > >4 > >ficy > >9 > >3 > >5/2/2017 > >bope > >100 > >stja > >5 > > > >4 > >5/2/2017 > >stgu > >87 > >stja > >6 > >bope > >20 > >5 > >5/2/2017 > >bg > >13 > >stja > >2 > >ficy > >10 > >6 > >5/2/2017 > >bope > >8 > >sirh > >3 > >stgu > >2 > > > >The problem is that the species were not recorded in any particular >order, >and not all species occur in every quadrat. There can also be any >number >of species per quadrat. I need to be able to extract each species AND >it?s >respective coverage, and place them in into another dataframe for >further >analysis > >So the result for ?bope? from above example data would look like this: > >Quadrat# > >% coverage bope > >1 > >0 > >2 > >75 > >3 > >100 > >4 > >20 > >5 > >0 > >6 > >8 > > > >Any help greatly appreciated. > >Brian > > [[alternative HTML version deleted]] > >______________________________________________ >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.