[R] sequencial frequency table

Marc Schwartz marc_schwartz at comcast.net
Tue Jan 30 15:48:44 CET 2007


On Tue, 2007-01-30 at 10:03 -0300, Mauricio Cardeal wrote:
> Hi.
> 
> I have the data frame xyz below and I´d like to perform a sequencial 
> frequency table using some unique function instead of making 3 different 
> one-by-one table (table x, table y and table z). But I´can´t figure out 
> the correct way.
> 
> x <- c(2,3,2,4)
> y <- c(3,1,1,1)
> z <- c(4,2,1,4)
> xyz <- as.data.frame(cbind(x,y,z))
> 
> freq <- function(x){
> table(x)
> }
> 
> freq(xyz)
> 
> Thank you,
> Mauricio

Is that what you want?

> lapply(xyz, table)
$x

2 3 4 
2 1 1 

$y

1 3 
3 1 

$z

1 2 4 
1 1 2 


See ?lapply if so.


HTH,

Marc Schwartz



More information about the R-help mailing list