[R] how to replace <NA> values

John Sorkin JSorkin at grecc.umaryland.edu
Mon Jan 20 15:06:49 CET 2014

I hope the code below will show you how to co what you want to do.

Elder1 <- data.frame(
# The age variable is a factor, we want it to be numeric
# Convert factor to a numeric value.
# Below you will see how you can test a value to see if it is NA.
# Replace the NA values with a zero.
# The final data frame with NAs replaced by zeros.

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing) 
>>> kingsly <ecokingsly at yahoo.co.in> 01/19/14 3:01 PM >>>
Dear R community
I have a large data set contain some empty cells. Because of that,  may be I am wrong, <NA> values are produced.
Now I want replace both empty and <NA> values with zero.
Elder1 <- data.frame(
Output I am expecting
ID   age
ID1  38
ID2  35
ID3  0
ID6  0
ID8  0
In advance I thank your help.

View this message in context: http://r.789695.n4.nabble.com/how-to-replace-NA-values-tp4683831.html
Sent from the R help mailing list archive at Nabble.com.
    [[alternative HTML version deleted]]

Confidentiality Statement:
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information.  Any unauthorized use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. 

More information about the R-help mailing list