Skip to content
Prev 167192 / 398502 Next

faster version of split()?

Hi all,

I want to calculate the number of unique observations of "y" in each level 
of "x" from my data frame "df".

this does the job but it is very slow for this big data frame (159503 rows, 
11 columns).....

group.list <- split(df$y,df$x)
count <- function(x) length(unique(na.omit(x)))
sapply(group.list, count, USE.NAMES=TRUE)

I couldnt find the answer searching for "slow split" and "split time" on 
help forum.

I am running R version 2.2.1, on a machine with 4gb of memory and I'm using 
windows 2000.

thanks in advance,

Simon.







----- Original Message ----- 
From: "Wacek Kusnierczyk" <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no>
To: "Gundala Viswanath" <gundalav at gmail.com>
Cc: "R help" <R-help at stat.math.ethz.ch>
Sent: Friday, January 16, 2009 9:30 AM
Subject: Re: [R] Value Lookup from File without Slurping