[R] pattern of panel waves using R

David Winsemius dwinsemius at comcast.net
Fri Mar 18 15:00:53 CET 2011


On Mar 17, 2011, at 11:40 PM, Sebastián Daza wrote:

> Hi everyone,
>
> Is there any command to identify the pattern of responses of a  
> database with this format:
>
> year  id
> 2008	1
> 2009	1
> 2008	2
> 2009	2
> 2008	3
> 2009	3
> 2008	4
> 2009	4
> 2010	4

Two methods assuming this is in a a data.frmae named `dat` and you  
want cross-tabulation:

tapply(dat$year, dat$id, length)

`xtabs` offers a more flexible method

xtabs(year ~ id, data=dat)

-- 
David.
>
>
> I just need the frequency of the patterns grouped by id:
>
> 2008 2009 2010 = 80

I don't understand what format this might be specifying. If you offer  
an example you should also specify the correct output from that  
example rather than the output from a larger example whose content you  
make the reader guess at. I cannot see any connection between the  
numbers 80, 30, and 10 with the example above, nor cann is see a  
connection with the set 2008, 2009, and 2010 with anything other than  
the set of objects associated with id==4. So its possible that the  
first step in your desired process might be the split function.

 > split(dat, dat$id)
$`1`
   year id
1 2008  1
2 2009  1

$`2`
   year id
3 2008  2
4 2009  2

$`3`
   year id
5 2008  3
6 2009  3

$`4`
   year id
7 2008  4
8 2009  4
9 2010  4


)

>        2009 2010 = 30
> 2008 2009         = 10
> and so on....
>
> Thank you in advance!
>
> -- 


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list