[R] How to replace all NA values in a data.frame with another ( not 0) value
I need to replace NA occurrences in multiple columns in a data.frame with 000/000 how do I achieve this? Thanks Nevil Amos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all NA values in a data.frame with another ( not 0) value
Try: x[which(is.na(x)),] - 000/000, where is x is your data frame - Lanna Jin lanna...@gmail.com 510-898-8525 -- View this message in context: http://r.789695.n4.nabble.com/How-to-replace-all-NA-values-in-a-data-frame-with-another-not-0-value-tp2125458p2125464.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all NA values in a data.frame with another ( not 0) value
Whoops, my bad. Maybe try using gsub - Lanna Jin lanna...@gmail.com 510-898-8525 -- View this message in context: http://r.789695.n4.nabble.com/How-to-replace-all-NA-values-in-a-data-frame-with-another-not-0-value-tp2125458p2125471.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all NA values in a data.frame with another ( not 0) value
000/000 returns NaN, which is no different than NA unless you want it as string i.e. 000/000 Muhammad Lanna Jin wrote: Try: x[which(is.na(x)),] - 000/000, where is x is your data frame - Lanna Jin lanna...@gmail.com 510-898-8525 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all NA values in a data.frame with another ( not 0) value
Hi Nevil, You can try a method like this x - c(rnorm(5),rep(NA,3),rnorm(5)) # sample data dat - data.frame(x,x) # make sample dataframe dat2 - as.matrix(dat) # conver to matrix y - which(is.na(dat)==TRUE) # get index of NA values dat2[y] - 000/000 # replace all na values with 000/000 Muhammad Nevil Amos wrote: I need to replace NA occurrences in multiple columns in a data.frame with 000/000 how do I achieve this? Thanks Nevil Amos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all NA values in a data.frame with another ( not 0) value
?replace Something like this should work replace(df1, is.na(df1), 000/000) --- On Tue, 5/4/10, Nevil Amos nevil.a...@gmail.com wrote: From: Nevil Amos nevil.a...@gmail.com Subject: [R] How to replace all NA values in a data.frame with another ( not 0) value To: r-h...@stat.math.ethz.ch Received: Tuesday, May 4, 2010, 8:54 AM I need to replace NA occurrences in multiple columnsĀ in a data.frame with 000/000 how do I achieve this? Thanks Nevil Amos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all NA values in a data.frame with another ( not 0) value
try x[is.na(x)] - 000/000 Bart -- View this message in context: http://r.789695.n4.nabble.com/How-to-replace-all-NA-values-in-a-data-frame-with-another-not-0-value-tp2125458p2125509.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all NA values in a data.frame with another ( not 0) value
Thanks, this works, replacing the NA values with the 000/000' string. On 4/05/2010 11:20 PM, Muhammad Rahiz wrote: Hi Nevil, You can try a method like this x - c(rnorm(5),rep(NA,3),rnorm(5)) # sample data dat - data.frame(x,x) # make sample dataframe dat2 - as.matrix(dat) # conver to matrix y - which(is.na(dat)==TRUE) # get index of NA values dat2[y] - 000/000 # replace all na values with 000/000 Muhammad Nevil Amos wrote: I need to replace NA occurrences in multiple columns in a data.frame with 000/000 how do I achieve this? Thanks Nevil Amos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.