Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

casting error - Error in .subset2(x, i, exact = exact)

Tags:

r

reshape2

It feels like I'm missing something obvious here, so apologies in advance. Anyways, here's some data a that I'm trying to cast:

acct_num     year_prem    prem       exc
001          2012         2763585 exclusive
001          2011         2377688 exclusive
001          2010         2083065 exclusive
001          2009         1751722 exclusive
001          2008         1639484 exclusive

However, casting gives me an error that I haven't been able to figure out / interpret:

b <- dcast(a, formula= acct_num + exc ~ year_prem, value.var= prem, fill= NA)

Error in .subset2(x, i, exact = exact) : invalid subscript type 'list'

I don't think that I need fill= NA. But I get the same error with or without it. Any help would be appreciated.

like image 857
Alex W Avatar asked Apr 16 '13 16:04

Alex W


1 Answers

You should put prem in quotes and then it works. Function dcast() expect that value.var= will be name of the column (so quoted).

> dcast(a, formula= acct_num + exc ~ year_prem, value.var= "prem", fill= NA)
  acct_num       exc    2008    2009    2010    2011    2012
1        1 exclusive 1639484 1751722 2083065 2377688 2763585
like image 85
Didzis Elferts Avatar answered Sep 30 '22 05:09

Didzis Elferts