Question: DataFrame matrix subsetting
gravatar for felix.ernst
10 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))
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
      [,1] [,2]

In comparison using data.frame

df2 <-
[1] NA NA NA

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


ADD COMMENTlink modified 10 months ago by Hervé Pagès ♦♦ 14k • written 10 months ago by felix.ernst0
Answer: DataFrame matrix subsetting
gravatar for Hervé Pagès
10 months ago by
Hervé Pagès ♦♦ 14k
United States
Hervé Pagès ♦♦ 14k 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

Thanks, H.

ADD COMMENTlink written 10 months ago by Hervé Pagès ♦♦ 14k

Hi Herve,

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


ADD REPLYlink written 9 months ago by felix.ernst0
Please log in to add an answer.


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