[R] RE SHAPE package question.

hpdutra hpdutra at yahoo.com
Sat Aug 2 23:00:08 CEST 2008


I am sorry but here is an example 
> test
  t1 t2 t3 t4 M F id
1  1  0  0  0 1 0  1
2  1  0  0  0 1 0  1
3  1  0  0  0 0 1  1
4  1  0  1  1 1 0  1
5  1  0  1  1 1 0  1
6  1  0  1  1 1 0  1
7  1  0  1  1 0 1  1

> test<-read.table(h=T, file.choose())
> dfm <- melt(test, m = "id")
> summarised <- cast(dfm, t1+ t2 + t3 + t4 + M + F ~ variable, sum)
> summarised
  t1 t2 t3 t4 M F id
1  1  0  0  0 0 1  1
2  1  0  0  0 1 0  2
3  1  0  1  1 0 1  1
4  1  0  1  1 1 0  3



So it works partially because it does not add the male and females columns.
I am sure it is simple but I just don't know how to do it. I was hoping that
it would give me the following data
  t1 t2 t3 t4 M F id
1  1  0  0  0 2 1  1
2  1  0  1  1 3 1  1


Many thanks!





hpdutra wrote:
> 
> Hi there, 
> 
> I am trying to reorganized my data sets so that it is easy for MARK to
> read it. 
> Basically I have the encounter histories of 1837 butterflies
> The data looks like this the first 4 columns are the occasions and the
> last two code for male and female
> 
>> t1  t2  t3  t4   M   F
>> 1    0   0    0   1   0  male capture on time1 but not seen on time 2, 3
>> and 4
>> 1    0   0    0   1   0  male capture on time1 but not seen on time 2, 3
>> and 4
>> 1    0   0    0   0   1  female capture on time1 but not seen on times 2,
>> 3 and 4
>> 1    0   1    1   1   0  male captured on time 1, not seen on time 2,
>> recaptured on time 3 and 4
>> 1    0   1    1   1   0  female captured on time 1, not seen on time 2,
>> recaptured on occasions 3 and 4
>> 1    0   1    1   1   0  female captured on time 1, not seen on time 2,
>> recaptured on occasions 3 and 4
>> 1    0   1    1   1   0  female captured on time 1, not seen on time 2,
>> recaptured on occasions 3 and 4
> 
> and I want to convert that into
> 
>>t1  t2  t3  t4   M  F
>> 1    0   0    0   2  1   Two males and 1 female captured on time1 but not
>> seen on time 2, 3 and 4
>> 1    0   1    1   1  3   One male and two females captured on time 1 and
>> , not seen on time 2, recaptured
>                                 on time 3 and 4
> 
> I tried to melt it using reshape, but I am getting odd results!
> 
> Any help is good help!
> 

-- 
View this message in context: http://www.nabble.com/RESHAPE-package-question.-tp18792801p18793300.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list