简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM