[R] FW: averaging two tables (rows with columns)

John Kane jrkrideau at inbox.com
Thu May 10 19:49:08 CEST 2012


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



More information about the R-help mailing list