Re: [R] NA values for "col"
On Mon, 27 Sep 2021 14:54:53 -0700 Bert Gunter wrote: > ... and also note in the *Color Specification* section of ?par, to > which ?points points, > > "Additionally, "transparent" is transparent, useful for filled areas > (such as the background!), and just invisible for things like lines or > text. In most circumstances (integer) NA is equivalent to > "transparent" (but not for text and mtext)." > > So an NA specification for col (or part of col, if a vector) plots the > point in "transparent" rather than omitting it. > > Now if your question is *why* the specifications for a color of NA are > different in points() and text(), I don't have a clue. But the > difference is documented. Thanks Bert. Clear enuff! cheers, Rolf -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] NA values for "col"
... and also note in the *Color Specification* section of ?par, to which ?points points, "Additionally, "transparent" is transparent, useful for filled areas (such as the background!), and just invisible for things like lines or text. In most circumstances (integer) NA is equivalent to "transparent" (but not for text and mtext)." So an NA specification for col (or part of col, if a vector) plots the point in "transparent" rather than omitting it. Now if your question is *why* the specifications for a color of NA are different in points() and text(), I don't have a clue. But the difference is documented. Bert On Mon, Sep 27, 2021 at 2:43 PM Bert Gunter wrote: > > ?text says > > "... NA values of font are replaced by par("font"), and similarly for col." > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > On Mon, Sep 27, 2021 at 2:12 PM Rolf Turner wrote: > > > > > > I've just noticed what seems to me to be somewhat peculiar behaviour in > > respect of how different plotting functions treat a specification > > "col=NA". > > > > Consider: > > > > plot(1:10) > > text(4,6,labels="o",col=NA) > > points(6,4,col=NA) > > > > The symbol produced by the call to text() shows up (is black). > > The symbol produced by the call to points() does not appear. > > > > Of course if one simply does > > > > points(6,4) > > > > then the symbol appears. > > > > This seems to me to be a mild inconsistency. > > > > It is No Big Deal, and in fact doesn't matter at all (who in their > > right mind would specify col=NA?). I only noticed this phenomenon > > because of an error I had made in some code. I'm just curious as to > > what is going on. Is there a reason for the difference in behaviour > > between text() and points()? (And plot(); plot(1:10,col=NA) produces > > no points in the plot.) > > > > Note that the help for par() says: > > > > > Some functions such as lines and text accept a vector of values which > > > are recycled and may be interpreted slightly differently. > > > > So I guess differences in behaviour are hinted at. > > > > I'm still curious! > > > > Any thoughts from anyone? > > > > cheers, > > > > Rolf Turner > > > > -- > > Honorary Research Fellow > > Department of Statistics > > University of Auckland > > Phone: +64-9-373-7599 ext. 88276 > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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 -- To UNSUBSCRIBE and more, see 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] NA values for "col"
?text says "... NA values of font are replaced by par("font"), and similarly for col." Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Sep 27, 2021 at 2:12 PM Rolf Turner wrote: > > > I've just noticed what seems to me to be somewhat peculiar behaviour in > respect of how different plotting functions treat a specification > "col=NA". > > Consider: > > plot(1:10) > text(4,6,labels="o",col=NA) > points(6,4,col=NA) > > The symbol produced by the call to text() shows up (is black). > The symbol produced by the call to points() does not appear. > > Of course if one simply does > > points(6,4) > > then the symbol appears. > > This seems to me to be a mild inconsistency. > > It is No Big Deal, and in fact doesn't matter at all (who in their > right mind would specify col=NA?). I only noticed this phenomenon > because of an error I had made in some code. I'm just curious as to > what is going on. Is there a reason for the difference in behaviour > between text() and points()? (And plot(); plot(1:10,col=NA) produces > no points in the plot.) > > Note that the help for par() says: > > > Some functions such as lines and text accept a vector of values which > > are recycled and may be interpreted slightly differently. > > So I guess differences in behaviour are hinted at. > > I'm still curious! > > Any thoughts from anyone? > > cheers, > > Rolf Turner > > -- > Honorary Research Fellow > Department of Statistics > University of Auckland > Phone: +64-9-373-7599 ext. 88276 > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 -- To UNSUBSCRIBE and more, see 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] NA values for "col"
I've just noticed what seems to me to be somewhat peculiar behaviour in respect of how different plotting functions treat a specification "col=NA". Consider: plot(1:10) text(4,6,labels="o",col=NA) points(6,4,col=NA) The symbol produced by the call to text() shows up (is black). The symbol produced by the call to points() does not appear. Of course if one simply does points(6,4) then the symbol appears. This seems to me to be a mild inconsistency. It is No Big Deal, and in fact doesn't matter at all (who in their right mind would specify col=NA?). I only noticed this phenomenon because of an error I had made in some code. I'm just curious as to what is going on. Is there a reason for the difference in behaviour between text() and points()? (And plot(); plot(1:10,col=NA) produces no points in the plot.) Note that the help for par() says: > Some functions such as lines and text accept a vector of values which > are recycled and may be interpreted slightly differently. So I guess differences in behaviour are hinted at. I'm still curious! Any thoughts from anyone? cheers, Rolf Turner -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] NA values in package KFAS or SSPIR
Hi, I tried to manage exponential family state-space model with the packages KFAS and sspir. The problem is that my data set includes some NA observation and it seems not working. Any suggestion? Thanks in advance, Federico -- View this message in context: http://r.789695.n4.nabble.com/NA-values-in-package-KFAS-or-SSPIR-tp3027877p3027877.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.
[R] NA values
Hi, I tried to manage exponential family state-space model with the packages KFAS. The problem is that my data set includes some NA observation and it seems not working. Any suggestion? Thanks in advance, Federico -- View this message in context: http://r.789695.n4.nabble.com/R-pkgs-New-package-for-multivariate-Kalman-filtering-smoothing-simulation-and-forecasting-tp903589p3027907.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] NA values in indexing
On Fri, Mar 26, 2010 at 4:15 PM, Matthew Dowle wrote: > The type of 'NA' is logical. So x[NA] behaves more like x[TRUE] i.e. silent > recycling. > >> class(NA) > [1] "logical" >> x=101:108 >> x[NA] > [1] NA NA NA NA NA NA NA NA >> x[c(TRUE,NA)] > [1] 101 NA 103 NA 105 NA 107 NA > >> x[as.integer(NA)] > [1] NA > > HTH Ouch. What is happening is that a numeric vector containing NA has become a logical vector of all NA because "‘NA’ is a logical constant of length 1" [?NA] Obviously R doesn't know that my c(NA,NA) came from c(4,NA,NA) and not c(TRUE,NA,NA). And it prints them the same: > NA_integer_ [1] NA > NA [1] NA Oh well, one to remember. I've got an urge to go eat a baNANA now. Barry __ 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] NA values in indexing
On Fri, Mar 26, 2010 at 4:15 PM, Bert Gunter wrote: > Is this, from the man page, relevant? > > "An empty index selects all values: this is most often used to replace all > the entries but keep the attributes. " No, I think that means doing "x[]", and only in replacement: > x=101:105 > attr(x,"foo")="Fnord" > x [1] 101 102 103 104 105 attr(,"foo") [1] "Fnord" > x[] [1] 101 102 103 104 105 attr(,"foo") [1] "Fnord" > x[]=1:5 > x [1] 1 2 3 4 5 attr(,"foo") [1] "Fnord" as you see, I've replaced all the entries but kept the attributes. c(NA,NA,NA) is clearly not empty... Barry __ 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] NA values in indexing
Is this, from the man page, relevant? "An empty index selects all values: this is most often used to replace all the entries but keep the attributes. " Bert Gunter Genentech Nonclinical Statistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Barry Rowlingson Sent: Friday, March 26, 2010 5:10 AM To: r-help@r-project.org Subject: [R] NA values in indexing If you index a vector with a vector that has NA in it, you get NA back: > x=101:107 > x[c(NA,4,NA)] [1] NA 104 NA > x[c(4,NA)] [1] 104 NA All well and good. ?"[" says, under NAs in indexing: When extracting, a numerical, logical or character 'NA' index picks an unknown element and so returns 'NA' in the corresponding element of a logical, integer, numeric, complex or character result, and 'NULL' for a list. (It returns '00' for a raw result.] But if the indexing vector is all NA, you get back a vector of length of your original vector rather than of your index vector: > x[c(NA,NA)] [1] NA NA NA NA NA NA NA Maybe it's just me, but I find this surprising, and I can't see it documented. Bug or undocumented feature? Apologies if I've missed something obvious. Barry sessionInfo() R version 2.11.0 alpha (2010-03-25 r51407) i686-pc-linux-gnu locale: [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_GB.UTF-8LC_COLLATE=en_GB.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_GB.UTF-8 [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base __ 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] NA values in indexing
Try > x <- 101:107 > x[c(NA_integer_, NA_integer_)] [1] NA NA On Fri, Mar 26, 2010 at 8:09 AM, Barry Rowlingson wrote: > If you index a vector with a vector that has NA in it, you get NA back: > > > x=101:107 > > x[c(NA,4,NA)] > [1] NA 104 NA > > x[c(4,NA)] > [1] 104 NA > > All well and good. ?"[" says, under NAs in indexing: > > When extracting, a numerical, logical or character ‘NA’ index > picks an unknown element and so returns ‘NA’ in the corresponding > element of a logical, integer, numeric, complex or character > result, and ‘NULL’ for a list. (It returns ‘00’ for a raw > result.] > > But if the indexing vector is all NA, you get back a vector of length > of your original vector rather than of your index vector: > > > x[c(NA,NA)] > [1] NA NA NA NA NA NA NA > > Maybe it's just me, but I find this surprising, and I can't see it > documented. Bug or undocumented feature? Apologies if I've missed > something obvious. > > Barry > > sessionInfo() > R version 2.11.0 alpha (2010-03-25 r51407) > i686-pc-linux-gnu > > locale: > [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8 > [5] LC_MONETARY=C LC_MESSAGES=en_GB.UTF-8 > [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > __ > 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] NA values in indexing
The type of 'NA' is logical. So x[NA] behaves more like x[TRUE] i.e. silent recycling. > class(NA) [1] "logical" > x=101:108 > x[NA] [1] NA NA NA NA NA NA NA NA > x[c(TRUE,NA)] [1] 101 NA 103 NA 105 NA 107 NA > x[as.integer(NA)] [1] NA HTH Matthew "Barry Rowlingson" wrote in message news:d8ad40b51003260509y6b671e53o9f79142d2b52c...@mail.gmail.com... If you index a vector with a vector that has NA in it, you get NA back: > x=101:107 > x[c(NA,4,NA)] [1] NA 104 NA > x[c(4,NA)] [1] 104 NA All well and good. ?"[" says, under NAs in indexing: When extracting, a numerical, logical or character NA index picks an unknown element and so returns NA in the corresponding element of a logical, integer, numeric, complex or character result, and NULL for a list. (It returns 00 for a raw result.] But if the indexing vector is all NA, you get back a vector of length of your original vector rather than of your index vector: > x[c(NA,NA)] [1] NA NA NA NA NA NA NA Maybe it's just me, but I find this surprising, and I can't see it documented. Bug or undocumented feature? Apologies if I've missed something obvious. Barry sessionInfo() R version 2.11.0 alpha (2010-03-25 r51407) i686-pc-linux-gnu locale: [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_GB.UTF-8LC_COLLATE=en_GB.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_GB.UTF-8 [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base __ 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] NA values in indexing
If you index a vector with a vector that has NA in it, you get NA back: > x=101:107 > x[c(NA,4,NA)] [1] NA 104 NA > x[c(4,NA)] [1] 104 NA All well and good. ?"[" says, under NAs in indexing: When extracting, a numerical, logical or character ‘NA’ index picks an unknown element and so returns ‘NA’ in the corresponding element of a logical, integer, numeric, complex or character result, and ‘NULL’ for a list. (It returns ‘00’ for a raw result.] But if the indexing vector is all NA, you get back a vector of length of your original vector rather than of your index vector: > x[c(NA,NA)] [1] NA NA NA NA NA NA NA Maybe it's just me, but I find this surprising, and I can't see it documented. Bug or undocumented feature? Apologies if I've missed something obvious. Barry sessionInfo() R version 2.11.0 alpha (2010-03-25 r51407) i686-pc-linux-gnu locale: [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_GB.UTF-8LC_COLLATE=en_GB.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_GB.UTF-8 [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base __ 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] NA values in Standard Error for zeroinfl()
I am fitting a model using zeroinfl() and it runs without errors, returning results that are generally consistent with my hypotheses. One of my variables is percent black (pblack). This variable was highly significant in some of the other count models I ran on the way to my current formulation. It is not significant in this model. As such I decided to try adding pblack^2 to the model to see whether the issue might captured there (if it matters I created a new variable in my data frame called pblacksqared and added that to the count portion of the model only). zeroinfl() runs just fine and pblack becomes significant and moves in the appropriate direction once the new variable is added to the model. However, pblacksquared is not significant, and while a coefficient is generated, I get NA values for Std. Error, z value and Pr(>|z|). pblack and pblacksquared are both positive and continuous with no missing values. I can't find anything in the documentation about returning an NA value here. Any suggestions as to where it comes from and how I might interpret/remedy it? Thanks, Chris __ 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] NA values trimming
Thanks again for all the help, now I was able to write the function I need: namax <- function(m,mp) { # arguments: matrix, maximum percentage of NA values allowed in rows/colums c1 <- 0 c2 <- 0 repeat { nas1 <- rowMeans(is.na(m)) nas2 <- colMeans(is.na(m)) if (max(nas1)max(nas2)) { idx <- which(nas1==max(nas1))[1] iname <- sub('[[:space:]]+$', '', names(idx)) cat("Row",iname,"contains",max(nas1)*100,"percent NAs.\n") m <- m[-idx,] c1 <- c1 + 1 } else { idx <- which(nas2==max(nas2))[1] iname <- sub('[[:space:]]+$', '', names(idx)) cat("Column",iname,"contains",max(nas2)*100,"percent NAs.\n") m <- m[,-idx] c2 <- c2 + 1 } } cat("Removed",c1,"rows and",c2,"columns.\n") return(m) } -- View this message in context: http://www.nabble.com/NA-values-trimming-tp24339399p24352605.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] NA values trimming
Thanks a lot, this works! The one I used before was wrong: > data_matrix [,1] [,2] [,3] [,4] [,5] [1,]11 NA11 [2,]22222 [3,]33333 [4,] NA NA NA NA NA [5,]55555 [6,] NA66 NA6 [7,] NA NA NA NA NA > nas1a <- apply(data_matrix,1,function(x)sum(is.na(x))/nrow(data_matrix)) > nas1b <- rowMeans(is.na(data_matrix)) > nas1a [1] 0.1428571 0.000 0.000 0.7142857 0.000 0.2857143 0.7142857 > nas1b [1] 0.2 0.0 0.0 1.0 0.0 0.4 1.0 -- View this message in context: http://www.nabble.com/NA-values-trimming-tp24339399p24351956.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] NA values trimming
On Mon, Jul 6, 2009 at 12:12 AM, nyk wrote: > > Thanks for your reply! This is what I was looking for! > I'm using > nas1 <- apply(data_matrix,1,function(x)sum(is.na(x))/nrow(data_matrix)) > nas2 <- apply(data_matrix,2,function(x)sum(is.na(x))/ncol(data_matrix)) You can simplify this a little: perc_missing <- function(x) mean(is.na(x)) nas1 <- apply(data_matrix,1, perc_missing) nas2 <- apply(data_matrix,2, perc_missing) or if your matrix is really big the following should be faster: nas1 <- rowMeans(is.na(data_matrix)) nas2 <- colMeans(is.na(data_matrix)) Hadley -- http://had.co.nz/ __ 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] NA values trimming
Thanks for your reply! This is what I was looking for! I'm using nas1 <- apply(data_matrix,1,function(x)sum(is.na(x))/nrow(data_matrix)) nas2 <- apply(data_matrix,2,function(x)sum(is.na(x))/ncol(data_matrix)) The thing about "significantly more" isn't really a helpful as I look at the data now. I better write a function that removes the row or column with the highest fraction of NAs, which I'll repeat as many times as it takes to get useful data. For example, I want to do heatmaps and dendrograms, but the data has too many NA values, so I get "Error in hclustfun(distfun(x)) : NA/NaN/Inf in foreign function call (arg 11)" David Winsemius wrote: > > > On Jul 4, 2009, at 9:22 PM, nyk wrote: > >> >> I have a data matrix containing quite a lot of missing values (NA). >> I know >> how to remove all column or rows containing NA values, but is there >> a some >> standard method for removing not all NA containing rows/column, but >> only >> those which have significantly more NAs than others? > > You have not defined what you mean by "significantly more than the > others" so perhaps all you want to know is haw to count the NA's in a > vector: > > > x=c(1,2,3,NA, 5,6,NA) > > sum(is.na(x)) > [1] 2 >> > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > __ > 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. > > -- View this message in context: http://www.nabble.com/NA-values-trimming-tp24339399p24347436.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] NA values trimming
On Jul 4, 2009, at 9:22 PM, nyk wrote: I have a data matrix containing quite a lot of missing values (NA). I know how to remove all column or rows containing NA values, but is there a some standard method for removing not all NA containing rows/column, but only those which have significantly more NAs than others? You have not defined what you mean by "significantly more than the others" so perhaps all you want to know is haw to count the NA's in a vector: > x=c(1,2,3,NA, 5,6,NA) > sum(is.na(x)) [1] 2 David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] NA values trimming
I have a data matrix containing quite a lot of missing values (NA). I know how to remove all column or rows containing NA values, but is there a some standard method for removing not all NA containing rows/column, but only those which have significantly more NAs than others? -- View this message in context: http://www.nabble.com/NA-values-trimming-tp24339399p24339399.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.
[R] NA-values and logical operation
Dear list, as a result of a logical operation I want to assign a new variable to a DF with NA-values. z <- data.frame( x = c(5,6,5,NA,7,5,4,NA), y = c(1,2,2,2,2,2,2,2) ) p <- (z$x <= 5) & (z$y == 1) p z[p, "p1"] <-5 z # ok, this works fine z <- z[,-3] p <- (z$x <= 5) & (z$y == 2) p z[p, "p2"] <-5 z # this failed... - how can I assign the value '5' to the new # var "p2" Thanks for any help!! Patrick __ 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] NA values
Yes, thanks a lot! It works fine! Eleni On Nov 21, 2007 2:03 PM, Ted Harding <[EMAIL PROTECTED]> wrote: > > On 21-Nov-07 11:15:32, Eleni Christodoulou wrote: > > Hi all! > > I am new to R and I would like to ask you the following question: > > How can I substitute the NA values with 0 in a data frame? > > I cannot find a command to check if a value is NA... > > > > Thank you very much! > > Eleni > > As has been said, is.na() is the function which determines > whether something has "value" NA (result=TRUE) or not (result=FALSE). > > is.na() will work nicely with dataframes (also, of course, with > structures such as vectors, matrices and arrays). Example: > > dummy<-data.frame(X1=c(101,102,103,104,NA,106), > X2=c(201,202,203,NA,205,206)) > > dummy > # X1 X2 > #1 101 201 > #2 102 202 > #3 103 203 > #4 104 NA > #5 NA 205 > #6 106 206 > > dummy[is.na(dummy)] <- 0 > > dummy > # X1 X2 > #1 101 201 > #2 102 202 > #3 103 203 > #4 104 0 > #5 0 205 > #6 106 206 > > Hoping this makes it clear! > Ted. > > > E-Mail: (Ted Harding) <[EMAIL PROTECTED]> > Fax-to-email: +44 (0)870 094 0861 > Date: 21-Nov-07 Time: 12:03:33 > -- XFMail -- > __ 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] NA values
On 21-Nov-07 11:15:32, Eleni Christodoulou wrote: > Hi all! > I am new to R and I would like to ask you the following question: > How can I substitute the NA values with 0 in a data frame? > I cannot find a command to check if a value is NA... > > Thank you very much! > Eleni As has been said, is.na() is the function which determines whether something has "value" NA (result=TRUE) or not (result=FALSE). is.na() will work nicely with dataframes (also, of course, with structures such as vectors, matrices and arrays). Example: dummy<-data.frame(X1=c(101,102,103,104,NA,106), X2=c(201,202,203,NA,205,206)) dummy # X1 X2 #1 101 201 #2 102 202 #3 103 203 #4 104 NA #5 NA 205 #6 106 206 dummy[is.na(dummy)] <- 0 dummy # X1 X2 #1 101 201 #2 102 202 #3 103 203 #4 104 0 #5 0 205 #6 106 206 Hoping this makes it clear! Ted. E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 21-Nov-07 Time: 12:03:33 -- XFMail -- __ 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] NA values
?is.na On Nov 21, 2007 12:15 PM, Eleni Christodoulou <[EMAIL PROTECTED]> wrote: > Hi all! > > I am new to R and I would like to ask you the following question:How > can I substitute the NA values with 0 in a data frame? I cannot find a > command to check if a value is NA... > > Thank you very much! > Eleni > > __ > 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. > [[alternative HTML version deleted]] __ 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] NA values
Eleni, this question appears about every month on this list, try using the RSiteSearch command before posting. Thanks. RSiteSearch("replace NA") http://finzi.psych.upenn.edu/R/Rhelp02a/archive/109176.html Gabor On Wed, Nov 21, 2007 at 01:15:32PM +0200, Eleni Christodoulou wrote: > Hi all! > > I am new to R and I would like to ask you the following question:How > can I substitute the NA values with 0 in a data frame? I cannot find a > command to check if a value is NA... > > Thank you very much! > Eleni > > __ > 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. -- Csardi Gabor <[EMAIL PROTECTED]>MTA RMKI, ELTE TTK __ 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] NA values
Hi all! I am new to R and I would like to ask you the following question:How can I substitute the NA values with 0 in a data frame? I cannot find a command to check if a value is NA... Thank you very much! Eleni __ 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.