且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用向量中的 NA 替换空条目

更新时间:2023-01-13 15:26:22

有一个函数以您要执行的操作命名:replace().

There is a function named after exactly what you are trying to do: replace().

有了它,你可以:

> V<- c("","Axe","Saw","")
> V
[1] ""    "Axe" "Saw" ""   
> replace(V, V == "", NA)
[1] NA    "Axe" "Saw" NA 

这就像说用 NA"替换向量 'V' 中任何等于 '""' 的值.所以,这不是您问题标题的逐字转录,但非常接近:-)

That's like saying "replace in the vector 'V' any values equal to '""' with NA". So, it's not a word-for-word transcription of your question title, but it is pretty close :-)