Question: DataFrame matrix subsetting
0
gravatar for felix.ernst
3 months ago by
felix.ernst0 wrote:

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

ADD COMMENTlink modified 3 months ago by Hervé Pagès ♦♦ 13k • written 3 months ago by felix.ernst0
Answer: DataFrame matrix subsetting
0
gravatar for Hervé Pagès
3 months ago by
Hervé Pagès ♦♦ 13k
United States
Hervé Pagès ♦♦ 13k wrote:

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 COMMENTlink written 3 months ago by Hervé Pagès ♦♦ 13k

Hi Herve,

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

Felix

ADD REPLYlink written 12 weeks ago by felix.ernst0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 146 users visited in the last hour