Skip to content
Prev 343083 / 398506 Next

New reshape2 question

Hi all,

Thanks go out to those who provided helpful suggestions last year with a 
similar issue.

I am working with a new data set and trying what I assumed was a simple 
aggregation in reshape2 but is not working.  I have a large number of 
similar data sets to run so getting the code correct is important.

I have tried this code line in bold (both plyr and reshape2 are loaded):

 > ChenaPond <- read.table("C:/Bat papers in prep/Chile/Data & 
analyses/ChenaPond.txt",header=T,sep="\t",quote="")
dat1<-ChenaPond
 >*res2<-ddply(dat1,.(Location,Species),summarize, Time=sum(Time))*

*Error in Summary.factor(c(3L, 4L, 5L, 15L, 39L, 45L, 18L, 24L, 25L, 
26L,  :
   sum not meaningful for factors*

Attached is the data.  Not sure why it is all factors and when I tried 
changing to double precision the times were corrupted.  I recall that R 
does not do well with time values.  Do I need a line using chron as well 
beforehand?

I even tried for several hours looking at the ReshapeGUI package to see 
what I may have been doing incorrectly to no avail.

 1. What I need to do to analyze all the data in another program is to
    reformat it so that I have a Species by Time matrix summarized in 5
    minute time blocks.  The result needs to be Species as rows, and
    time intervals are arranged chronologically in columns.
 2. Then I need the matrix converted such that each unique Species will
    have proportional abundances of time (0 to 100) so totals for each
    species should be the same (or 100%).


What do folks suggest?
Plyr, Reshape2 or try tables?

Thanks,

Bruce