DataFrame matrix subsetting
1
0
Entering edit mode
@felixernst-13698
Last seen 4.9 years ago

Hi all,

I am not sure, whether this example should work or works as intended

df <- DataFrame(one = c(1,2,3), two = c(NA,NA,NA))
df[is.na(df)]
Error: subscript is a logical vector with out-of-bounds TRUE values
In addition: Warning message:
In NSBS(i, x, exact = exact, strict.upper.bound = !allow.append,  :
  subscript is an array, passing it thru as.vector() first

The logical matrix seams to be reasonable valid

is.na(df)
      [,1] [,2]
[1,] FALSE TRUE
[2,] FALSE TRUE
[3,] FALSE TRUE

In comparison using data.frame

df2 <- as.data.frame(df)
df[is.na(df)]
[1] NA NA NA

Any advice or suggestions? Did I miss something obvious? Is the use case I described discouraged somehow?

Best

DataFrame subsetting S4Vectors • 1.5k views
ADD COMMENT
0
Entering edit mode
@herve-pages-1542
Last seen 2 days ago
Seattle, WA, United States

Hi Felix,

My guess is that the [ method for DataFrame objects doesn't know how to handle a logical matrix subscript in a way that mimics what happens with ordinary data frames or matrices. Note that in such case df[m] can simply be obtained with as.matrix(df)[m] so the workaround is pretty straightforward. The point could be made that the error message produced by df[m] doesn't really help though.

Might be worth opening an issue here https://github.com/Bioconductor/S4Vectors/issues

Thanks, H.

ADD COMMENT
0
Entering edit mode

Hi Herve,

thanks for the answer. I will look into opening an issue.

Felix

ADD REPLY

Login before adding your answer.

Traffic: 532 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6