Я использую функцию:
if(nrow(product$productCC) > 0){
product$productCC$type
claimsInvoice[, CCtype := product$productCC$type]
claimsInvoice[, ':=' (CCtype = product$productCC$type)]
}
, но в обоих случаях я получаю ошибку. Хотя я с помощью ': =' была функциональной формой?
> product$productCC$type
[1] "GENERAL_CAP_PER_YEAR"
> claimsInvoice[, CCtype := product$productCC$type]
Error in product$productCC : $ operator is invalid for atomic vectors
Как это можно исправить?
РЕДАКТИРОВАТЬ:
Я пытался использовать
type <- product$productCC$type
claimsInvoice[, ':=' (CCtype = type)]
вместо
claimsInvoice[, CCtype := product$productCC$type]
, чтобы избежать проблем с областями видимости, упомянутых @ chinsoon12, но это приводит к другой ошибке:
Warning message:
In `[.data.table`(claimsInvoice, , `:=`(CCtype = type)) :
Coercing 'character' RHS to 'logical' to match the type of the target column (column 13 named 'CCtype').