简体   繁体   中英

How can I add 1 to all integers in a dataset consiting integers and NAs (in R)?

I have a dataset consisting of integers and NAs. I want to add 1 (+1) to all of the integers but not to the NAs. How can I do this? Thanks for your help!

Assuming your df is named df and var1 is the column you want to add 1 to:

df$var2 = df$var1 +1

where var2 will be the column having the final result.

PS Adding 1 to NA still returns NA.

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