從我的簡單data.table,例如,像這樣:「object」ansvals'not found「錯誤 - 這是什麼意思?
dt1 <- fread("
col1 col2 col3
AAA ab cd
BBB ef gh
BBB ij kl
CCC mn nm")
我想提出新的表格,例如,像這樣:
dt1[,
.(col3, new=.N),
by=col1]
> col1 col3 new
>1: AAA cd 1
>2: BBB gh 2
>3: BBB kl 2
>4: CCC op 1
這工作得很好,當我指出的列名明確。但是,當我讓他們在變量,並嘗試使用with=F
,這給出了一個錯誤:
colBy <- 'col1'
colShow <- 'col3'
dt1[,
.(colShow, 'new'=.N),
by=colBy,
with=F]
# Error in `[.data.table`(dt1, , .(colShow, new = .N), by = colBy, with = F) : object 'ansvals' not found
我找不到任何關於此錯誤的任何信息爲止。
謝謝你的解釋!當列名存儲在變量中時,它是否意味着只有'by ='才能使用? –
@VasilyA這當然是可能的,但你必須以正確的方式做到這一點。見[這裏](http://stackoverflow.com/questions/32940580/convert-some-column-classes-in-data-table/32942319#32942319)或[這裏](http://stackoverflow.com/questions/ 33772830/how-to-set-multiple-columns-and-selected-rows-in-data-table-to-value-from-other/33774525#33774525)舉例。您可能還想閱讀[入門指南](https://github.com/Rdatatable/data.table/wiki/Getting-started) – Jaap
,在這些例子中,by ='完全不用,這個使它變得非常不同......我將再次閱讀入門指南,並可能發佈一個單獨的問題,指明我確實需要什麼。 –