Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206316

Cross tabs/frequency tables with long-form longitudinal data in R

$
0
0

I have a longitudinal dataset with data in long format (one row for each time point for each participant), and I would like to get cross tabs for demographic variables at each time point. Simplified, say I wanted a table with the number of participants of a certain sex (row) and race (column) for each of 3 time points ("Time" variable).

Something like this:

Time = 1

        White    Black  Total
Male    10       11
Female  9        12
total   19       23     42

And a sample data set:

Participant Time Race Sex
1           1    White Male 
1           2    NA    NA 
1           3    White Male 
2           2    Black Male
2           3    Black Male
2           NA   NA    NA
3           1    Black Female    
3           NA   NA    NA
3           NA   NA    NA

I can do this individually by subsetting the dataset by each wave, but I was unable to figure out how to do it all together/at once, if possible, without having to subset the data into new datasets. Ideally, it would also include % in each cell and total sample sizes as well.

Thank you!


Viewing all articles
Browse latest Browse all 206316

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>