Hi R user,I am struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your help would be grateful- I am spending so much time to figure it out. It should not be so hard, I think. I have very big data but I have created a hypothetical data for simplification. for example I have : table 1 table 1: species occurance data speciesX speciesY speciesZ speciesXX Plot1 1 0 1 0 Plot2 0 1 1 0 Plot3 0 0 0 1 Plot4 1 0 1 0 Table 2 table 2. species tolerance data EnviA EnviB EnviC speciesX 0.21 0.4 0.17 speciesY 0.1 0.15 0.18 speciesXX 0.14 0.16 0.19 You may noticed that table 2 does not have species Z which was in table 1. Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc)The example of the out come (final table I was looking for it) Results table 1a: average species tolerance in each plot based on EnviA Result Table 3. Average species tolerance in each plot based on EnviA speciesX speciesY speciesZ speciesXX Average Plot1 0.21 NA Nodata 0.14 0.175 Plot2 NA 0.1 Nodata NA 0.1 Plot3 NA NA Nodata 0.14 0.14 Plot4 0.21 NA Nodata NA 0.21 Result table 1b: average species tolerance in plot based on EnviB Table 4. Average species tolerance in each plot based on EnviB speciesX speciesY speciesZ speciesXX Average Plot1 0.4 NA Nodata 0.16 0.28 Plot2 NA 0.15 Nodata NA 0.15 Plot3 NA NA Nodata 0.16 0.16 Plot4 0.4 NA Nodata NA 0.4 Would any one help me how I can calculate these?Thanks Kristi Golver===== [[alternative HTML version deleted]]
Kristi, Your data has come through in a totally unreadable layout. Have a look at ?dput as a handy way to present sample data. Just run dput(mydata), copy the output and paste into the email. John Kane Kingston ON Canada> -----Original Message----- > From: kristi.glover at hotmail.com > Sent: Thu, 10 May 2012 12:50:43 -0300 > To: r-help at r-project.org > Subject: [R] averaging two tables (rows with columns) > > > Hi R user,I am struggling to figure out on how I can calculate the > average from the two tables in R. Any one can help me? really your help > would be grateful- I am spending so much time to figure it out. It should > not be so hard, I think. > I have very big data but I have created a hypothetical data for > simplification. > for example > I have : table 1 > > > > > table 1: species occurance data > > > > > > > > > > > > > > > > > speciesX > > > speciesY > > > speciesZ > > > speciesXX > > > > > Plot1 > > > 1 > > > 0 > > > 1 > > > 0 > > > > > Plot2 > > > 0 > > > 1 > > > 1 > > > 0 > > > > > Plot3 > > > 0 > > > 0 > > > 0 > > > 1 > > > > > Plot4 > > > 1 > > > 0 > > > 1 > > > 0 > > > > > Table 2 > > > > table 2. species tolerance data > > > > > > > > > > > > > EnviA > > > EnviB > > > EnviC > > > > > speciesX > > > 0.21 > > > 0.4 > > > 0.17 > > > > > speciesY > > > 0.1 > > > 0.15 > > > 0.18 > > > > > speciesXX > > > 0.14 > > > 0.16 > > > 0.19 > > > > You may noticed that table 2 does not have species Z which was in table > 1. > > > Now I want to get the average value of species tolerance in each plot > based on each environmental value (EnviA or EnviB etc)The example of the > out come (final table I was looking for it) Results table 1a: average > species tolerance in each plot based on EnviA > > > > > Result Table 3. Average species tolerance in each plot based on EnviA > > > > > > > > > speciesX > > > speciesY > > > speciesZ > > > speciesXX > > > Average > > > > > Plot1 > > > 0.21 > > > NA > > > Nodata > > > 0.14 > > > 0.175 > > > > > Plot2 > > > NA > > > 0.1 > > > Nodata > > > NA > > > 0.1 > > > > > Plot3 > > > NA > > > NA > > > Nodata > > > 0.14 > > > 0.14 > > > > > Plot4 > > > 0.21 > > > NA > > > Nodata > > > NA > > > 0.21 > > > > > Result table 1b: average species tolerance in plot based on EnviB > > > > Table 4. Average species tolerance in each plot based on EnviB > > > > > > > > > speciesX > > > speciesY > > > speciesZ > > > speciesXX > > > Average > > > > > Plot1 > > > 0.4 > > > NA > > > Nodata > > > 0.16 > > > 0.28 > > > > > Plot2 > > > NA > > > 0.15 > > > Nodata > > > NA > > > 0.15 > > > > > Plot3 > > > NA > > > NA > > > Nodata > > > 0.16 > > > 0.16 > > > > > Plot4 > > > 0.4 > > > NA > > > Nodata > > > NA > > > 0.4 > > > > > Would any one help me how I can calculate these?Thanks > Kristi Golver=====> > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Hi as already mentioned your data can not be deciphered. Use dput(table1) for sending usable data.>From what you describe probably?aggregate can be used. But without suitable data you hardly get any advice. Regards Petr> > > Hi R user,I am struggling to figure out on how I can calculate theaverage> from the two tables in R. Any one can help me? really your help wouldbe> grateful- I am spending so much time to figure it out. It should not beso> hard, I think. > I have very big data but I have created a hypothetical data forsimplification.> for example > I have : table 1 > > > > > table 1: species occurance data > > > > > > > > > > > > > > > > > speciesX > > > speciesY > > > speciesZ > > > speciesXX > > > > > Plot1 > > > 1 > > > 0 > > > 1 > > > 0 > > > > > Plot2 > > > 0 > > > 1 > > > 1 > > > 0 > > > > > Plot3 > > > 0 > > > 0 > > > 0 > > > 1 > > > > > Plot4 > > > 1 > > > 0 > > > 1 > > > 0 > > > > > Table 2 > > > > table 2. species tolerance data > > > > > > > > > > > > > EnviA > > > EnviB > > > EnviC > > > > > speciesX > > > 0.21 > > > 0.4 > > > 0.17 > > > > > speciesY > > > 0.1 > > > 0.15 > > > 0.18 > > > > > speciesXX > > > 0.14 > > > 0.16 > > > 0.19 > > > > You may noticed that table 2 does not have species Z which was in table1.> > > Now I want to get the average value of species tolerance in each plot > based on each environmental value (EnviA or EnviB etc)The example of the> out come (final table I was looking for it) Results table 1a: average > species tolerance in each plot based on EnviA > > > > > Result Table 3. Average species tolerance in each plot based on EnviA > > > > > > > > > speciesX > > > speciesY > > > speciesZ > > > speciesXX > > > Average > > > > > Plot1 > > > 0.21 > > > NA > > > Nodata > > > 0.14 > > > 0.175 > > > > > Plot2 > > > NA > > > 0.1 > > > Nodata > > > NA > > > 0.1 > > > > > Plot3 > > > NA > > > NA > > > Nodata > > > 0.14 > > > 0.14 > > > > > Plot4 > > > 0.21 > > > NA > > > Nodata > > > NA > > > 0.21 > > > > > Result table 1b: average species tolerance in plot based on EnviB > > > > Table 4. Average species tolerance in each plot based on EnviB > > > > > > > > > speciesX > > > speciesY > > > speciesZ > > > speciesXX > > > Average > > > > > Plot1 > > > 0.4 > > > NA > > > Nodata > > > 0.16 > > > 0.28 > > > > > Plot2 > > > NA > > > 0.15 > > > Nodata > > > NA > > > 0.15 > > > > > Plot3 > > > NA > > > NA > > > Nodata > > > 0.16 > > > 0.16 > > > > > Plot4 > > > 0.4 > > > NA > > > Nodata > > > NA > > > 0.4 > > > > > Would any one help me how I can calculate these?Thanks > Kristi Golver=====> > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Hi R-usuar, I still find the table is not in readable formate. I now forwarded the email.hope it works. I sent it to my account . It was perfect- but when I sent it to R help- then it comes with unreadable formate. This is my last try. If not, then I will try to do in Excel manually. cheers, From: kristi.glover@hotmail.com To: kristi.glover@hotmail.com Subject: RE: [R] averaging two tables (rows with columns) Date: Thu, 10 May 2012 14:06:41 -0300 Hi John , Petr and R userI am sorry that my data was not readable formate in the last email. Agin I am trying to send it. hope this time, that table can be readable. As I mentioned earlier that I was struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your helpwould be grateful- I am spending so much time to figure it out. It should not be so hard, I think.I have very big data but I have created a hypothetical data for simplification.for example I have : table 1 Table 1: species occurrence data> table1 X speciesX speciesY speciesZ speciesXX1 Plot1 1 0 1 02 Plot2 0 1 1 03 plot3 1 0 0 14 plot4 0 0 1 0 Table 2: table 2. species tolerance data>table2 X EnviA EnviB EnviC1 SpeciesX 0.21 0.40 0.172 SpeciesY 0.10 0.15 0.183 SpeciesXY 0.14 0.16 0.19You may noticed that table 2 does not have species Z which was in table Table 3: Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc).The example of the out come (final table I was looking for it). Results table 1a: averages species tolerance in each plot based on EnviA such as:> table3.a X speciesX speciesY speciesZ speciesXX average1 plot1 0.21 NA Nodata 0.14 0.1752 plot2 NA 0.1 Nodata NA 0.1003 plot3 NA NA Nodata 0.14 0.1404 plot4 0.21 NA Nodata NA 0.210Table 4> table3.b: Result table 1b: average species tolerance in plot based on EnviB X speciesX speciesY speciesZ speciesXX average1 plot1 0.4 NA Nodata 0.16 0.282 plot2 NA 0.15 Nodata NA 0.153 plot3 NA NA Nodata 0.16 0.164 plot4 0.4 NA Nodata NA 0.40I hope this time the data would be readable formate. Would any one help me how I can calculate these?Thanks Kristi Golver=> Date: Thu, 10 May 2012 08:01:11 -0800 > From: jrkrideau@inbox.com > Subject: RE: [R] averaging two tables (rows with columns) > To: kristi.glover@hotmail.com; r-help@r-project.org > > Kristi, > Your data has come through in a totally unreadable layout. > > Have a look at ?dput as a handy way to present sample data. Just run dput(mydata), copy the output and paste into the email. > > John Kane > Kingston ON Canada >[[alternative HTML version deleted]]
Kristi The tables , if read in edit mode are vagely readable but please just do as Petr and I suggest. Use the dput command. If you have the table in an R data.frame all you need to do is use the command dput(mytable) I read your two tables into R and did that . Note I called them dat1 & dat2. table is a command in R and it is best not to use it as a variable name. Results 1> dput(dat1) structure(list(X = c("Plot1", "Plot2", "plot3", "plot4"), speciesX = c(1L, 0L, 1L, 0L), speciesY = c(0L, 1L, 0L, 0L), speciesZ = c(1L, 1L, 0L, 1L), speciesXX = c(0L, 0L, 1L, 0L)), .Names = c("X", "speciesX", "speciesY", "speciesZ", "speciesXX"), class = "data.frame", row.names = c(NA, -4L)) 1> dput(dat2) structure(list(X = c("SpeciesX", "SpeciesY", "SpeciesXY"), EnviA = c(0.21, 0.1, 0.14), EnviB = c(0.4, 0.15, 0.16), EnviC = c(0.17, 0.18, 0.19)), .Names = c("X", "EnviA", "EnviB", "EnviC"), class = "data.frame", row.names = c("1", "2", "3")) 1> Now you just need to stick variable name and an <- in front of the dput material and paste it into R Like THIS mytable1 <- structure(list(X = c("Plot1", "Plot2", "plot3", "plot4"), speciesX = c(1L, 0L, 1L, 0L), speciesY = c(0L, 1L, 0L, 0L), speciesZ = c(1L, 1L, 0L, 1L), speciesXX = c(0L, 0L, 1L, 0L)), .Names = c("X", "speciesX", "speciesY", "speciesZ", "speciesXX"), class = "data.frame", row.names = c(NA, -4L)) and paste it into R. Now we probably can get somewhere. John Kane Kingston ON Canada> -----Original Message----- > From: kristi.glover at hotmail.com > Sent: Thu, 10 May 2012 14:18:50 -0300 > To: r-help at r-project.org > Subject: [R] FW: averaging two tables (rows with columns) > > > Hi R-usuar, > I still find the table is not in readable formate. I now forwarded the > email.hope it works. I sent it to my account . It was perfect- but when I > sent it to R help- then it comes with unreadable formate. This is my last > try. If not, then I will try to do in Excel manually. cheers, > > From: kristi.glover at hotmail.com > To: kristi.glover at hotmail.com > Subject: RE: [R] averaging two tables (rows with columns) > Date: Thu, 10 May 2012 14:06:41 -0300 > > > > > > Hi John , Petr and R userI am sorry that my data was not readable formate > in the last email. Agin I am trying to send it. hope this time, that > table can be readable. > As I mentioned earlier that I was struggling to figure out on how I can > calculate the average from the two tables in R. Any one can help me? > really your helpwould be grateful- I am spending so much time to figure > it out. It should not be so hard, I think.I have very big data but I have > created a hypothetical data for simplification.for example > I have : table 1 > Table 1: species occurrence data> table1 X speciesX speciesY > speciesZ speciesXX1 Plot1 1 0 1 02 Plot2 > 0 1 1 03 plot3 1 0 0 > 14 plot4 0 0 1 0 > > Table 2: table 2. species tolerance data > >table2 X EnviA EnviB EnviC1 SpeciesX 0.21 0.40 > 0.172 SpeciesY 0.10 0.15 0.183 SpeciesXY 0.14 0.16 0.19 > > You may noticed that table 2 does not have species Z which was in table > > Table 3: Now I want to get the average value of species tolerance in each > plot based on each environmental value (EnviA or EnviB etc).The example > of the out come (final table I was looking for it). > Results table 1a: averages species tolerance in each plot based on EnviA > such as: >> table3.a X speciesX speciesY speciesZ speciesXX average1 plot1 >> 0.21 NA Nodata 0.14 0.1752 plot2 NA 0.1 >> Nodata NA 0.1003 plot3 NA NA Nodata 0.14 >> 0.1404 plot4 0.21 NA Nodata NA 0.210Table 4 > >> table3.b: Result table 1b: average species tolerance in plot based on >> EnviB X speciesX speciesY speciesZ speciesXX average1 plot1 >> 0.4 NA Nodata 0.16 0.282 plot2 NA 0.15 >> Nodata NA 0.153 plot3 NA NA Nodata 0.16 >> 0.164 plot4 0.4 NA Nodata NA 0.40 > I hope this time the data would be readable formate. Would any one help > me how I can calculate these?Thanks > Kristi Golver=> > > >> Date: Thu, 10 May 2012 08:01:11 -0800 >> From: jrkrideau at inbox.com >> Subject: RE: [R] averaging two tables (rows with columns) >> To: kristi.glover at hotmail.com; r-help at r-project.org >> >> Kristi, >> Your data has come through in a totally unreadable layout. >> >> Have a look at ?dput as a handy way to present sample data. Just run >> dput(mydata), copy the output and paste into the email. >> >> John Kane >> Kingston ON Canada >> > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
Well I'd suggest learning to use the return key. It really helps improve the readability of a posting. Three of the for files came through okay but table3a has a problem. It looks like some kind of extraneous charater(s) got into it but a second or so of editing makes it work so we have all 4 tables now. John Kane Kingston ON Canada> -----Original Message----- > From: kristi.glover at hotmail.com > Sent: Thu, 10 May 2012 14:36:51 -0300 > To: r-help at r-project.org > Subject: Re: [R] FW: averaging two tables (rows with columns) > > > oppps, Now I used 'dput' function. Again I am sending. I am so sorry for > inconvenience. > HI R userI am sorry that my data was not readable formate in the last > email. Agin I am trying to send it. hope this time, that table can be > readable.As I mentioned earlier that I was struggling to figure out on > how I can calculate the average from the two tables in R. Any one can > help me? really your helpwould be grateful- I am spending so much time to > figure it out. It should not be so hard, I think.I have very big data but > I have created a hypothetical data for simplification.for exampleI have : > table 1Table 1: species occurrence data> dput(table1)structure(list(X > structure(1:4, .Label = c("Plot1", "Plot2", "plot3", "plot4"), class > "factor"), speciesX = c(1L, 0L, 1L, 0L), speciesY = c(0L, 1L, 0L, 0L), > speciesZ = c(1L, 1L, 0L, 1L), speciesXX = c(0L, 0L, 1L, 0L)), .Names > c("X", "speciesX", "speciesY", "speciesZ", "speciesXX"), class > "data.frame", row.names = c(NA, -4L)) > Table 2: table 2. species tolerance data> dput(table2)structure(list(X > structure(c(1L, 3L, 2L), .Label = c("SpeciesX", "SpeciesXY", "SpeciesY"), > class = "factor"), EnviA = c(0.21, 0.1, 0.14), EnviB = c(0.4, 0.15, > 0.16), EnviC = c(0.17, 0.18, 0.19)), .Names = c("X", "EnviA", "EnviB", > "EnviC"), class = "data.frame", row.names = c(NA, -3L))> You may noticed > that table 2 does not have species Z which was in tableTable 3: Now I > want to get the average value of species tolerance in each plot based on > each environmental value (EnviA or EnviB etc).The example of the out come > (final table I was looking for it).Results table 3a: averages species > tolerance in each plot based on EnviAsuch as: > > dput(table3a)structure(list(X = structure(1:4, .Label = c("plot1", > "plot2", "plot3", "plot4"), class = "factor"), speciesX = c(0.21, NA, NA, > 0.21), speciesY = c(NA, 0.1, NA, NA), speciesZ = structure(c(1L, 1L, 1L, > 1L), .Label = "Nodata", class = "factor"), speciesXX = c(0.14, NA, 0.14, > NA), av! > erage = c(0.175, 0.1, 0.14, 0.21)), .Names = c("X", "speciesX", > "speciesY", "speciesZ", "speciesXX", "average"), class = "data.frame", > row.names = c(NA, -4L)) > Table 3b > Result table 3b: average species tolerance in plot based on EnviB> > dput(table3b) structure(list(X = structure(1:4, .Label = c("plot1", > "plot2", "plot3", "plot4"), class = "factor"), speciesX = c(0.4, NA, NA, > 0.4), speciesY = c(NA, 0.15, NA, NA), speciesZ = structure(c(1L, 1L, 1L, > 1L), .Label = "Nodata", class = "factor"), speciesXX = c(0.16, NA, 0.16, > NA), average = c(0.28, 0.15, 0.16, 0.4)), .Names = c("X", "speciesX", > "speciesY", "speciesZ", "speciesXX", "average"), class = "data.frame", > row.names = c(NA, -4L))I hope this time the data would be readable > formate. Would any one help me how I can calculate these?ThanksKristi > Golver=> > > again > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.____________________________________________________________ Send your photos by email in seconds... TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if3 Works in all emails, instant messengers, blogs, forums and social networks.
Kristi Glover
2012-May-10 22:03 UTC
[R] how to do averaging of two tables (rows with columns)
Hi R user, I finally able to send you the table in readable format. I have seen that some of you do send tables in email when asking questions, but why i could not send. Any way some of you helped me to send you the example table in a readable format. now, I want to concentrate on my problem. I am trying to get the information (dat 3) from dat 1 and 2 in R. I have very big data but these data are just hypothetical data. my data structures are exactly same as dat 1 and dat 2. I created dat 3 and dat4 manually to show what information I wanted to have. I am struggling to figure it out how I can do in R. I think it is not difficult. I hope any one can help me. dat1 is the table of species occurrence (o means species absence, 1 means species presence). dat1 <- structure(list(X = structure(1:4, .Label = c("Plot1", "Plot2", "plot3", "plot4"), class = "factor"), speciesX = c(1L, 0L, 1L, 0L), speciesY = c(0L, 1L, 0L, 0L), speciesZ = c(1L, 1L, 0L, 1L), speciesXX = c(0L, 0L, 1L, 0L)), .Names = c("X", "speciesX", "speciesY", "speciesZ", "speciesXX"), class = "data.frame", row.names = c(NA, -4L)) dat2 is the species tolerances value in each environmental variable dat2 <- structure(list(X = structure(c(1L, 3L, 2L), .Label = c("SpeciesX", "SpeciesXX", "SpeciesY"), class = "factor"), EnviA c(0.21, 0.1, 0.14), EnviB = c(0.4, 0.15, 0.16), EnviC = c(0.17, 0.18, 0.19)), .Names c("X", "EnviA", "EnviB", "EnviC"), class = "data.frame", row.names = c(NA, -3L)) ## note (here in dat 2 there is no "species Z" you can see that ) Now, I want to get the average value of tolerances in each grid. like dat 3 the dat3 is based on the column EnviA. dat3 <-structure(list(X = structure(1:4, .Label = c("plot1", "plot2", "plot3", "plot4"), class = "factor"), speciesX = c(0.21, NA, NA, 0.21), speciesY = c(NA, 0.1, NA, NA), speciesZ = structure(c(1L, 1L, 1L, 1L), .Label = "Nodata", class = "factor"), speciesXX = c(0.14, NA, 0.14, NA), average = c(0.175, 0.1, 0.14, 0.21)), .Names = c("X", "speciesX", "speciesY", "speciesZ", "speciesXX", "average"), class = "data.frame", row.names = c(NA, -4L)) dat4 is same thing as dat3 but here i used EnviB instead of EnviA. dat4 <- structure(list(X = structure(1:4, .Label = c("plot1", "plot2", "plot3", "plot4"), class "factor"), speciesX = c(0.4, NA, NA, 0.4), speciesY = c(NA, 0.15, NA, NA), speciesZ structure(c(1L, 1L, 1L, 1L), .Label = "Nodata", class = "factor"), speciesXX = c(0.16, NA, 0.16, NA), average = c(0.28, 0.15, 0.16, 0.4)), .Names = c("X", "speciesX", "speciesY", "speciesZ", "speciesXX", "average"), class = "data.frame", row.names = c(NA, -4L)) I hope you understand my problem and you can help me. Thanks Kristi [[alternative HTML version deleted]]