简体   繁体   中英

NAs replace - r

I want to replace NA in columns campaign by "none". Campaign is character.

trx2[trx2$campaign=="<NA>"] <- "none"

but it gives me an error "missing values are not allowed in subscripted assignments of data frames".

Thank you for your help

The proper way to test for na values is is.na() ; moreover, you need to subset tr2x$campaign and not the whole data.frame. Hence :

trx2$campaign[is.na(trx2$campaign)] <- "none"

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