Re: [R] replace NA into - for specific column

2021-06-03 Thread konstantinos christodoulou
Hi Kai, You can also try this: proband_crc2 %>% mutate(MMR = replace(MMR, MMR =="NA", "-")) Thanks, Kostas On Wed, Jun 2, 2021 at 11:59 AM Jim Lemon wrote: > Hi Kai, > Maybe this will help: > > proband_crc2<-data.frame(MMR=rep(c(NA,"+"),3)) > proband_crc2 > proband_crc2$MMR[is.na(proband_cr

Re: [R] replace NA into - for specific column

2021-06-02 Thread Kai Yang via R-help
Hello Jim,Your example works well.Thank you for your help,Kai On Tuesday, June 1, 2021, 04:59:09 PM PDT, Kai Yang via R-help wrote: Hi List, I have a column MMR in a data frame proband_crc2. The column contents missing value and + (means positive).  I need to replace all missing value

Re: [R] replace NA into - for specific column

2021-06-02 Thread Jim Lemon
Hi Kai, Maybe this will help: proband_crc2<-data.frame(MMR=rep(c(NA,"+"),3)) proband_crc2 proband_crc2$MMR[is.na(proband_crc2$MMR)]<-"-" proband_crc2 Jim On Wed, Jun 2, 2021 at 9:59 AM Kai Yang via R-help wrote: > > Hi List, > I have a column MMR in a data frame proband_crc2. The column content

Re: [R] replace NA into - for specific column

2021-06-01 Thread Jeff Newmiller
A unary negative sign with no number is not a number, so it has to be character. If you are done with computations you can format your numbers as character data and set the NA to "-", but such a conversion will prevent you from performing computations so it is only useful for creating report tab

[R] replace NA into - for specific column

2021-06-01 Thread Kai Yang via R-help
Hi List, I have a column MMR in a data frame proband_crc2. The column contents missing value and + (means positive).  I need to replace all missing value into - (means negative) I did try with difference ways.  Below are my testing, but not any one works. Can someone help me? Thanks, Kai proband_

Re: [R] replace NA with another vector

2013-12-24 Thread arun
 z <- x  z[is.na(z)] <- y  z #[1] 20 40  3 50  1 A.K. On Tuesday, December 24, 2013 12:06 PM, Kathryn Lord wrote: Dear R users, I have two different vectors like below x <- c( NA, NA, 3, NA, 1) y <- c( 20, 40 ,50) Combining x and y, I'd like to create new vector z z <- c(20, 40, 3, 50, 1

[R] replace NA with another vector

2013-12-24 Thread Kathryn Lord
Dear R users, I have two different vectors like below x <- c( NA, NA, 3, NA, 1) y <- c( 20, 40 ,50) Combining x and y, I'd like to create new vector z z <- c(20, 40, 3, 50, 1) Any suggestion will be greatly appreciated. Best, Kathryn Lord [[alternative HTML version deleted]] _

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

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 >

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

2013-07-29 Thread William Dunlap
': 5 obs. of 3 variables: $ AllNAs : num NaN NaN NaN NaN NaN $ NoNAs : num 1 2 3 4 5 $ SomeNAs: cplx 100+1i 100+1i 100+1i ... Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r

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, -0.

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" 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 >

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 wrote: > Hi everyone > > I have a problem with replacing the NA values with the mean of the column > which contains them. If I repla

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)) popul

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" 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 >

[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

2011-05-06 Thread Joshua Wiley
Hi, If your geology map is a special kind of object, this may not work, but if you are just dealing with a data frame or matrix type object named, "geology" with columns, something like this ought to do the trick: geology[is.na(geology[, "landform"]), "landform"] <- 0 ?is.na returns a logical ve

[R] replace NA

2011-05-06 Thread azam jaafari
Hello all   I have a geology map that has three level, bellow   <-geology lithology    landscape   landform     landform level is used as covariate (with codes=1,2,3,4,5) for training of neural network, but this level has missing data as NA. I want to replace the missing data of landform level wi

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 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 = c("A1", NA, NA, NA, "B1",

[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 <- c(rownam

Re: [R] replace NA value with 0

2010-03-18 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 17.03.2010 18:01:50: > > Building on the question how to replace NA with 0. > > My data set below has date, station 1, flags for station 1, station 2, flags > for station 2, etc... > > I would like to make the values in the station columns equal to 1

Re: [R] replace NA value with 0

2010-03-17 Thread ehux
Building on the question how to replace NA with 0. My data set below has date, station 1, flags for station 1, station 2, flags for station 2, etc... I would like to make the values in the station columns equal to 1 and the NA in the station columns equal to 0 and then sum each row for the numbe

Re: [R] replace NA with 9999 in zoo object

2008-03-06 Thread Gabor Grothendieck
It works just the same as matrices: > z <- zoo(cbind(a = c(1, NA, 3), b = c(NA, 10, 11))) > z[is.na(z)] <- 999 > z a b 1 1 999 2 999 10 3 3 11 > There are also a number of other methods for handling NAs in zoo: na.approx na.contiguous na.locf na.spline na.trim and na.stinterp in the

[R] replace NA with 9999 in zoo object

2008-03-06 Thread stephen sefick
This is the same set of data that I have been working with for those in the know. it is a matrix of ~174 columns and ~70,000 rows. I have it as a zoo object, but I could read it in as just a matrix as long as the date time stamp won't be corrupted. here is an example of what a column would look

Re: [R] replace NA value with 0

2007-09-14 Thread John Kane
Seconded. --- Greg Snow <[EMAIL PROTECTED]> wrote: > > > > > -Original Message- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of > Gabor Csardi > > Sent: Friday, September 14, 2007 2:56 AM > > To: S Ellison > &

Re: [R] replace NA value with 0

2007-09-14 Thread Ted Harding
On 14-Sep-07 09:22:36, S Ellison wrote: > Being a chemist, I have to confess that I can't always tell > that what I'm about to attempt is barking, trivial, uninteresting > or better done a completely different way; myself, I'd rather be > warned too often than left to dig my own pit and fall into i

Re: [R] replace NA value with 0

2007-09-14 Thread Greg Snow
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Gabor Csardi > Sent: Friday, September 14, 2007 2:56 AM > To: S Ellison > Cc: [EMAIL PROTECTED] > Subject: Re: [R] replace NA value with 0 I nominate the following parag

Re: [R] replace NA value with 0

2007-09-14 Thread S Ellison
>>> Ted Harding <[EMAIL PROTECTED]> 14/09/2007 10:59:47 >>> >On the contrary! It adds to our "collective wisdom". > >We all have to suck eggs, and usually can successfully perform the act. Ted, Thanks for the kind remarks. But we'll have to get off the egg topic, or we'll all end up as acknowl

Re: [R] replace NA value with 0

2007-09-14 Thread Gabor Csardi
On Fri, Sep 14, 2007 at 10:22:36AM +0100, S Ellison wrote: [...] > knee-jerk. Apologies if I'm teaching egg-sucking to an expert. No apologies please. As i said I _like_ it. Thanks :) G > S > > *** > This email and any attachment

Re: [R] replace NA value with 0

2007-09-14 Thread S Ellison
>>On Fri, Sep 14, 2007 at 09:46:57AM +0100, S Ellison wrote: >> >>... only you probably shouldn't be doing that at all. Words like 'bias' >>spring to mind... >> >> Woudn't it be better to accept the NA's and find methods that handle them as >> genuinely missing. >> R is usually quite good at

Re: [R] replace NA value with 0

2007-09-14 Thread Gabor Csardi
On Fri, Sep 14, 2007 at 09:46:57AM +0100, S Ellison wrote: > > > >>> Gabor Csardi <[EMAIL PROTECTED]> 14/09/2007 09:27:03 >>> > >x[ is.na(x) ] <- 0 > > > >should work in most cases i think. > > ... only you probably shouldn't be doing that at all. Words like 'bias' > spring to mind... > > Woud

Re: [R] replace NA value with 0

2007-09-14 Thread S Ellison
>>> Gabor Csardi <[EMAIL PROTECTED]> 14/09/2007 09:27:03 >>> >x[ is.na(x) ] <- 0 > >should work in most cases i think. ... only you probably shouldn't be doing that at all. Words like 'bias' spring to mind... Woudn't it be better to accept the NA's and find methods that handle them as genuine

Re: [R] replace NA value with 0

2007-09-14 Thread Gabor Csardi
x[ is.na(x) ] <- 0 should work in most cases i think. Gabor On Fri, Sep 14, 2007 at 10:08:19AM +0200, Alfredo Alessandrini wrote: > Hi, > > how can I replace NA value with 0: > > 1991 217 119 103 109 137 202 283 240 146 NA > 1992 270 174 149 144 166 239 278 237 275 NA > 1993 146 111 104

[R] replace NA value with 0

2007-09-14 Thread Alfredo Alessandrini
Hi, how can I replace NA value with 0: 1991 217 119 103 109 137 202 283 240 146 NA 1992 270 174 149 144 166 239 278 237 275 NA 1993 146 111 104 89 98 131 153 148 175 NA 1994 177 123 146 124 121 200 266 191 240 106 1995 145 98 95 89 95 130 183 161 164 129 1996 145 98 89 90 93 13