Re: [R] Retaining attributes of columns of a data frame when subsetting.

2019-10-20 Thread Rolf Turner
On 21/10/19 11:07 AM, Rui Barradas wrote: Hello, Sorry, you're right, in the method it's x, X is the test dataframe. Repost: `[.myclass` <- function(x, i, j, drop = if (missing(i)) TRUE else length(cols) == 1){   SaveAt <- lapply(x, attributes)   x <- NextMethod()   lX <- lapply(names(x

Re: [R] Retaining attributes of columns of a data frame when subsetting.

2019-10-20 Thread Rui Barradas
Hello, Sorry, you're right, in the method it's x, X is the test dataframe. Repost: `[.myclass` <- function(x, i, j, drop = if (missing(i)) TRUE else length(cols) == 1){ SaveAt <- lapply(x, attributes) x <- NextMethod() lX <- lapply(names(x),function(nm, x, Sat){ attributes(x[[nm]]) <

Re: [R] Retaining attributes of columns of a data frame when subsetting.

2019-10-20 Thread Rolf Turner
On 21/10/19 1:15 AM, Rui Barradas wrote: Hello, Richard's idea is good but shouldn't it be `[.myclass` instead? Yes, I kind of thought that, and cobbled together something on that basis that seemed to work. However my code was rather a hodge-podge. I kept having to work around errors th

Re: [R] Retaining attributes of columns of a data frame when subsetting.

2019-10-20 Thread Rui Barradas
Hello, Richard's idea is good but shouldn't it be `[.myclass` instead? `[.myclass` <- function(x, i, j, drop = if (missing(i)) TRUE else length(cols) == 1){ SaveAt <- lapply(X, attributes) X <- NextMethod() lX <- lapply(names(X),function(nm, x, Sat){ attributes(x[[nm]]) <- Sat[[nm]]

Re: [R] Retaining attributes of columns of a data frame when subsetting.

2019-10-19 Thread Rolf Turner
On 20/10/19 3:00 PM, Richard M. Heiberger wrote: Look at methods(as.data.frame) Define your specialized columns to have a newly defined class, say "myclass". Then write as.data.frame.myclass It will be similar to the function you already have in the lapply statement. Now your statement X <- X[ok,

Re: [R] Retaining attributes of columns of a data frame when subsetting.

2019-10-19 Thread Richard M. Heiberger
Look at methods(as.data.frame) Define your specialized columns to have a newly defined class, say "myclass". Then write as.data.frame.myclass It will be similar to the function you already have in the lapply statement. Now your statement X <- X[ok,] should work. Rich On Sat, Oct 19, 2019 at 8:20