Re: [R] Replace NA values with previous valid value in array

2013-10-22 Thread arun
Hi, c1 = (1,2,3,4,5,6,NA,7,8,NA,9,10,NA) library(zoo) na.locf(c1) # [1]  1  2  3  4  5  6  6  7  8  8  9 10 10 A.K. Hi, I want to fix an array that contains several NA elements. And I would like to replace them with the previous valid element. So my array c = (1,2,3,4,5,6,NA,7,8,NA,9,10,NA)

[R] replace Na values with the mean of the column which contains them

2013-07-29 Thread iza.ch1
Hi everyone I have a problem with replacing the NA values with the mean of the column which contains them. If I replace Na with the means of the rest values in the column, the mean of the whole column will be still the same as if I would have omitted NA values. I have the following data de

Re: [R] replace Na values with the mean of the column which contains them

2013-07-29 Thread Berend Hasselman
On 29-07-2013, at 18:39, iza.ch1 iza@op.pl wrote: Hi everyone I have a problem with replacing the NA values with the mean of the column which contains them. If I replace Na with the means of the rest values in the column, the mean of the whole column will be still the same as if I

Re: [R] replace Na values with the mean of the column which contains them

2013-07-29 Thread John Fox
Dear iza.ch1, I hesitate to say this, because mean imputation is such a bad idea, but it's easy to do what you want with a loop, rather than puzzling over a cleverer way to accomplish the task. Here's an example using the Freedman data set in the car package: colSums(is.na(Freedman))

Re: [R] replace Na values with the mean of the column which contains them

2013-07-29 Thread Jorge I Velez
Consider the following: f - function(x){ m - mean(x, na.rm = TRUE) x[is.na(x)] - m x } apply(de, 2, f) HTH, Jorge.- On Tue, Jul 30, 2013 at 2:39 AM, iza.ch1 iza@op.pl wrote: Hi everyone I have a problem with replacing the NA values with the mean of the column which contains them. If

Re: [R] replace Na values with the mean of the column which contains them

2013-07-29 Thread Berend Hasselman
On 29-07-2013, at 18:39, iza.ch1 iza@op.pl wrote: Hi everyone I have a problem with replacing the NA values with the mean of the column which contains them. If I replace Na with the means of the rest values in the column, the mean of the whole column will be still the same as if I

Re: [R] replace Na values with the mean of the column which contains them

2013-07-29 Thread arun
Hi, de- structure(c(NA, NA, NA, NA, NA, NA, NA, NA, 0.27500571, -3.07568579, -0.42240954, -0.26901731, 0.01766284, -0.8099958, 0.20805934, 0.03036708, -0.26928087, 1.20925752, 0.38012008, -0.41778861, -0.49677462, -0.13248754, -0.54179054, 0.35788624, -0.41467591, -0.59234248, 0.73642396,

Re: [R] replace Na values with the mean of the column which contains them

2013-07-29 Thread William Dunlap
-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of arun Sent: Monday, July 29, 2013 10:58 AM To: iza.ch1 Cc: R help Subject: Re: [R] replace Na values with the mean of the column which contains them Hi, de- structure(c(NA, NA, NA, NA, NA, NA, NA, NA

Re: [R] replace Na values with the mean of the column which contains them

2013-07-29 Thread David Winsemius
On Jul 29, 2013, at 9:39 AM, iza.ch1 wrote: Hi everyone I have a problem with replacing the NA values with the mean of the column which contains them. If I replace Na with the means of the rest values in the column, the mean of the whole column will be still the same as if I would have

[R] replace NA-values

2010-06-21 Thread Patrick Hausmann
Dear list, I'm trying to replace NA-values with the preceding values in that column. This code works, but I am sure there is a more elegant way... df - data.frame(id = c(A1, NA, NA, NA, B1, NA, NA, C1, NA, NA, NA, NA), value = c(1:12)) rn -

Re: [R] replace NA-values

2010-06-21 Thread jim holtman
try 'na.locf' in the zoo package On Mon, Jun 21, 2010 at 7:52 AM, Patrick Hausmann patrick.hausm...@uni-bremen.de wrote: Dear list, I'm trying to replace NA-values with the preceding values in that column. This code works, but I am sure there is a more elegant way... df - data.frame(id =