Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-Forge #5437] By operations with factors #36

Closed
arunsrinivasan opened this issue Jun 8, 2014 · 0 comments
Closed

[R-Forge #5437] By operations with factors #36

arunsrinivasan opened this issue Jun 8, 2014 · 0 comments
Assignees
Labels
Milestone

Comments

@arunsrinivasan
Copy link
Member

Submitted by: Christophe Dervieux; Assigned to: Arun ; R-Forge link

Hi,

I have updated data.table package to 1.9.2 recently from 1.8.10 and I found errors on my previous code.

See reproductible example below:

On 1.8.10 :

DT <- data.table(X = factor(2006:2012), Y = rep(1:7, 2))
DT[, Z := paste(X, .N, sep = " - "), by = list(X)][]

       X     Y        Z
 1: 2006 1 2006 - 2
 2: 2007 2 2007 - 2
 3: 2008 3 2008 - 2
 4: 2009 4 2009 - 2
 5: 2010 5 2010 - 2
 6: 2011 6 2011 - 2
 7: 2012 7 2012 - 2
 8: 2006 1 2006 - 2
 9: 2007 2 2007 - 2
10: 2008 3 2008 - 2
11: 2009 4 2009 - 2
12: 2010 5 2010 - 2
13: 2011 6 2011 - 2
14: 2012 7 2012 - 2

In column Z, I get the level of the factor column X
pasted with count '.N' as expected

However, in the 1.9.2, with same code :

DT<-data.table(X=factor(2006:2012),Y=rep(1:7,2))
DT[,Z:=paste(X,.N,sep=" - "),by=list(X)][]

        X     Y  Z
 1: 2006 1 1 - 2
 2: 2007 2 2 - 2
 3: 2008 3 3 - 2
 4: 2009 4 4 - 2
 5: 2010 5 5 - 2
 6: 2011 6 6 - 2
 7: 2012 7 7 - 2
 8: 2006 1 1 - 2
 9: 2007 2 2 - 2
10: 2008 3 3 - 2
11: 2009 4 4 - 2
12: 2010 5 5 - 2
13: 2011 6 6 - 2
14: 2012 7 7 - 2

as results, I do not get levels of factor column X but the numeric values associated with the level.

is this working normally? Why has it changed? Is that a bug?

I use this kind of procedure to make labels for ggplot. All my previous code is not working anymore. It's kind of annoying.

Thanks

Christophe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant