Re: [R] subsetting without losing the attributes

2012-07-18 Thread Rui Barradas
Hello, Another quote from the help pages that could be usefull is, from ?subset, Warning This is a convenience function intended for use interactively. For programming it is better to use the standard subsetting functions like [, and in particular the non-standard evaluation of argument subse

Re: [R] subsetting without losing the attributes

2012-07-17 Thread Peter Ehlers
Inline On 2012-07-17 04:16, MK wrote: Hi, How do I use the subset function without losing the attributes? You don't. At least not without modifying subset.data.frame(). The key sentence on the ?Extract help page is this: "Subsetting (except by an empty index) will drop all attributes exc

[R] subsetting without losing the attributes

2012-07-17 Thread MK
Hi, How do I use the subset function without losing the attributes? For example, test.df <- data.frame(a = rnorm(100), b = runif(100), c = rexp(100)) attr(test.df[, 1], "units") <- c("cm") attr(test.df[, 2], "units") <- c("kg") attr(test.df[, 3], "units") <- c("ha") ## We want this behavior s