Re: [R] Why does R replace all row values with NAs

2015-03-01 Thread peter dalgaard
> On 27 Feb 2015, at 16:02 , Duncan Murdoch wrote: > > Yes. Indexing with a logical NA is probably a mistake, and this is one > way to signal it without actually triggering a warning or error. There are cases where it isn't (usually) a mistake, e.g. pch=c(25,24)[sex], where it is quite crucia

Re: [R] Why does R replace all row values with NAs

2015-02-27 Thread Dimitri Liakhovitski
Thank you very much guys! On Fri, Feb 27, 2015 at 11:04 AM, William Dunlap wrote: > You could define functions like >is.true <- function(x) !is.na(x) & x >is.false <- function(x) !is.na(x) & !x > and use them in your selections. E.g., > > x <- data.frame(a=1:10,b=2:11,c=c(1,NA,3,NA,5,N

Re: [R] Why does R replace all row values with NAs

2015-02-27 Thread William Dunlap
You could define functions like is.true <- function(x) !is.na(x) & x is.false <- function(x) !is.na(x) & !x and use them in your selections. E.g., > x <- data.frame(a=1:10,b=2:11,c=c(1,NA,3,NA,5,NA,7,NA,NA,10)) > x[is.true(x$c >= 6), ] a b c 7 7 8 7 10 10 11 10 Bill Dun

Re: [R] Why does R replace all row values with NAs

2015-02-27 Thread Duncan Murdoch
On 27/02/2015 10:27 AM, Dimitri Liakhovitski wrote: > Thank you very much, Duncan. > All this being said: > > What would you say is the most elegant and most safe way to solve such > a seemingly simple task? If you have NA values, test for them explicitly, e.g. your original x[(x$c<6) | is.na(x$

Re: [R] Why does R replace all row values with NAs

2015-02-27 Thread Dimitri Liakhovitski
Thank you very much, Duncan. All this being said: What would you say is the most elegant and most safe way to solve such a seemingly simple task? Thank you! On Fri, Feb 27, 2015 at 10:02 AM, Duncan Murdoch wrote: > On 27/02/2015 9:49 AM, Dimitri Liakhovitski wrote: >> So, Duncan, do I understan

Re: [R] Why does R replace all row values with NAs

2015-02-27 Thread Duncan Murdoch
On 27/02/2015 9:49 AM, Dimitri Liakhovitski wrote: > So, Duncan, do I understand you correctly: > > When I use x$x<6, R doesn't know if it's TRUE or FALSE, so it returns > a logical value of NA. Yes, when x$x is NA. (Though I think you meant x$c.) > When this logical value is applied to a row,

Re: [R] Why does R replace all row values with NAs

2015-02-27 Thread Dimitri Liakhovitski
So, Duncan, do I understand you correctly: When I use x$x<6, R doesn't know if it's TRUE or FALSE, so it returns a logical value of NA. When this logical value is applied to a row, the R says: hell, I don't know if I should keep it or not, so, just in case, I am going to keep it, but I'll replace

Re: [R] Why does R replace all row values with NAs

2015-02-27 Thread Duncan Murdoch
On 27/02/2015 9:04 AM, Dimitri Liakhovitski wrote: > I know how to get the output I need, but I would benefit from an > explanation why R behaves the way it does. > > # I have a data frame x: > x = data.frame(a=1:10,b=2:11,c=c(1,NA,3,NA,5,NA,7,NA,NA,10)) > x > # I want to toss rows in x that conta

[R] Why does R replace all row values with NAs

2015-02-27 Thread Dimitri Liakhovitski
I know how to get the output I need, but I would benefit from an explanation why R behaves the way it does. # I have a data frame x: x = data.frame(a=1:10,b=2:11,c=c(1,NA,3,NA,5,NA,7,NA,NA,10)) x # I want to toss rows in x that contain values >=6. But I don't want to toss my NAs there. subset(x,c