maechler@stat.math.ethz.ch
2000-Sep-21 08:18 UTC
[Rd] "[.data.frame" forgets about "AsIs" (PR#665)
Short example: > str(d <- data.frame(a = I(letters[1:5]))) `data.frame': 5 obs. of 1 variable: $ a:Class 'AsIs' chr [1:5] "a" "b" "c" "d" ... > str(d[TRUE,,drop = FALSE]) `data.frame': 5 obs. of 1 variable: $ a: chr "a" "b" "c" "d" ... The real problem about this is, that as soon as the data.frame is further "transformed", the character component is coerced to a factor, e.g. > str(rbind(d[TRUE,,drop = FALSE], "E")) `data.frame': 6 obs. of 1 variable: $ a: Factor w/ 6 levels "a","b","c","d",..: 1 2 3 4 6 5 --- I'm looking at a fix myself. Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
maechler@stat.math.ethz.ch
2000-Sep-21 15:56 UTC
[Rd] "[.data.frame" forgets about "AsIs" (PR#665)
>>>>> "MM" == Martin Maechler <maechler@stat.math.ethz.ch> writes:MM> Short example: >> str(d <- data.frame(a = I(letters[1:5]))) MM> `data.frame': 5 obs. of 1 variable: MM> $ a:Class 'AsIs' chr [1:5] "a" "b" "c" "d" ... >> str(d[TRUE,,drop = FALSE]) MM> `data.frame': 5 obs. of 1 variable: MM> $ a: chr "a" "b" "c" "d" ... MM> The real problem about this is, that as soon as the data.frame is MM> further "transformed", the character component is coerced to a MM> factor, e.g. >> str(rbind(d[TRUE,,drop = FALSE], "E")) MM> `data.frame': 6 obs. of 1 variable: MM> $ a: Factor w/ 6 levels "a","b","c","d",..: 1 2 3 4 6 5 Probably the cleanest fix is the addition of "[.AsIs" <- function(x, i) structure(NextMethod("["), class = class(x)) -- Will go into R-devel unless someone has a better idea. Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._