[R] How to extract last value in each group

arun smartpink111 at yahoo.com
Fri Aug 16 05:58:19 CEST 2013


Hi Steve,

Thanks.  The error problem is solved by using quotes.

Will post at data-table mailing list regarding the issue of:
 
system.time(ans <- dt1[, .SD[.N], by='Date'])
  # user  system elapsed 
# 39.284   0.000  39.352 


A.K.



----- Original Message -----
From: Steve Lianoglou <lianoglou.steve at gene.com>
To: arun <smartpink111 at yahoo.com>
Cc: R help <r-help at r-project.org>
Sent: Thursday, August 15, 2013 11:28 PM
Subject: Re: [R] How to extract last value in each group

Hi,

On Thu, Aug 15, 2013 at 4:03 PM, arun <smartpink111 at yahoo.com> wrote:
> HI Steve,
>
> Thanks for testing.
>
> When I run a slightly bigger dataset:
> set.seed(1254)
> name<- sample(letters,1e7,replace=TRUE)
> number<- sample(1:10,1e7,replace=TRUE)
>
> datTest<- data.frame(name,number,stringsAsFactors=FALSE)
> library(data.table)
>
> dtTest<- data.table(datTest)
>
> system.time(res3<- dtTest[,list(Sum_Number=sum(number)),by=name])
>  #user  system elapsed
>  # 0.592   0.028   0.623
>
> #Then I tried this:
>
> dtTest1<- data.table(datTest,key=name)
> #Error: C stack usage is too close to the limit
>
> Cstack_info()
> #      size    current  direction eval_depth
>  #  8388608       7320          1          2

Do you get this stack problem if you quote `name`, eg:

R> dtTest1 <- data.table(datTest, key="name")

?

Perhaps we should move this to data.table-help if you want to debug
further, though:

https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help

-steve

-- 
Steve Lianoglou
Computational Biologist
Bioinformatics and Computational Biology
Genentech




More information about the R-help mailing list