search for: unclass

Displaying 20 results from an estimated 513 matches for "unclass".

2005 Apr 02
4
factor to numeric in data.frame
Dear All, Assume I have a data.frame that contains also factors and I would like to get another data.frame containing the factors as numeric vectors, to apply functions like sapply(..., median) on them. I read the warning concerning as.numeric or unclass, but in my case this makes sense, because the factor levels are properly ordered. I can do it, if I write for each single column "unclass(...), but I would like to use indexing, e.g. unclass(df[1:10]). Is that possible? Thanks, Heinz T?chler ## Example: f1 <- factor(c(rep('c1-low'...
2017 Mar 07
0
length(unclass(x)) without unclass(x)?
...h of an object 'x' as given by > base data type without dispatching on class. The performance improvement you're looking for is implemented in the latest version of pqR (pqR-2016-10-24, see pqR-project.org), along with corresponding improvements in several other circumstances where unclass(x) does not create a copy of x. Here are some examples (starting with yours), using pqR's Rprofmemt function to get convenient traces of memory allocations: > Rprofmemt(nelem=1000) # trace allocations of vectors with >= 1000 elements > > x <- structure(double(1e6), clas...
2003 Aug 16
4
unclass
Have I been sleeping in class? rw1071 from CRAN, windows XP incidencia is made by a call to tapply > class(incidencia) [1] "array" > incidencia <- unclass(incidencia) > class(incidencia) [1] "array" Kjetil Halvorsen
2012 Dec 21
2
Why can't I "unclass" an array?
In a real example I was trying to remove the class from the result of table, just because it was to be used as a building block for other things and a simple integer vector seemed likely to be most efficient. I'm puzzled as to why unclass doesn't work. > zed <- table(1:5) > class(zed) [1] "table" > class(unclass(zed)) [1] "array" > class(unclass(unclass(unclass(zed)))) [1] "array" > class(as.vector(zed)) [1] "integer" > sessionInfo() R Under development (unstab...
2012 Dec 21
2
Why can't I "unclass" an array?
In a real example I was trying to remove the class from the result of table, just because it was to be used as a building block for other things and a simple integer vector seemed likely to be most efficient. I'm puzzled as to why unclass doesn't work. > zed <- table(1:5) > class(zed) [1] "table" > class(unclass(zed)) [1] "array" > class(unclass(unclass(unclass(zed)))) [1] "array" > class(as.vector(zed)) [1] "integer" > sessionInfo() R Under development (unstab...
2018 Sep 03
0
True length - length(unclass(x)) - without having to call unclass()?
Regarding the discussion of getting length(unclass(x)) without an unclassed version of x being created... There are already no copies done for length(unclass(x)) in pqR (current version of 2017-06-09 at pqR-project.org, as well as the soon-to-be-release new version). This is part of a more general facility for avoiding copies from unclass in othe...
2017 Mar 05
0
length(unclass(x)) without unclass(x)?
I'm looking for a way to get the length of an object 'x' as given by base data type without dispatching on class. Something analogous to how .subset()/.subset2(), e.g. a .length() function. I know that I can do length(unclass(x)), but that will trigger the creation of a new object unclass(x) which I want to avoid because 'x' might be very large. Here's a dummy example illustrating what I'm trying to get to: > x <- structure(double(1e6), class = c("foo", "numeric")) > length...
2018 Sep 05
0
True length - length(unclass(x)) - without having to call unclass()?
On 08/24/2018 07:55 PM, Henrik Bengtsson wrote: > Is there a low-level function that returns the length of an object 'x' > - the length that for instance .subset(x) and .subset2(x) see? An > obvious candidate would be to use: > > .length <- function(x) length(unclass(x)) > > However, I'm concerned that calling unclass(x) may trigger an > expensive copy internally in some cases. Is that concern unfounded? Unclass() will always copy when "x" is really a variable, because the value in "x" will be referenced; whether it is prohibi...
2018 Aug 24
5
True length - length(unclass(x)) - without having to call unclass()?
Is there a low-level function that returns the length of an object 'x' - the length that for instance .subset(x) and .subset2(x) see? An obvious candidate would be to use: .length <- function(x) length(unclass(x)) However, I'm concerned that calling unclass(x) may trigger an expensive copy internally in some cases. Is that concern unfounded? Thxs, Henrik
2018 Sep 01
0
True length - length(unclass(x)) - without having to call unclass()?
...<- function(x) { cls <- class(x) # setattr() does not make a copy, but modifies by reference data.table::setattr(x, "class", NULL) # get the length len <- base::length(x) # re-set original classes data.table::setattr(x, "class", cls) # return the unclassed length len } # to check that we do not make unwanted changes orig_class <- class(x) # check that the address in RAM does not change a1 <- data.table::address(x) # 'unclassed' length stopifnot(.length(x) == 2L) # check that address is the same stopifnot(a1 == data.table::addre...
2018 Sep 10
0
True length - length(unclass(x)) - without having to call unclass()?
...nrik Bengtsson wrote: >>> Is there a low-level function that returns the length of an object 'x' >>> - the length that for instance .subset(x) and .subset2(x) see? An >>> obvious candidate would be to use: >>> >>> .length <- function(x) length(unclass(x)) >>> >>> However, I'm concerned that calling unclass(x) may trigger an >>> expensive copy internally in some cases. Is that concern unfounded? >> Unclass() will always copy when "x" is really a variable, because the >> value in "x"...
2008 Feb 16
3
Arithmetic bug? (found when use POSIXct) (PR#10776)
...oblem when I'm doing something with POSIXct The code to reproduce it is as follows (This is the recommended way of finding out time zone difference on R News 2004-1 Page 32 URL http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf) a=Sys.time() b<-as.POSIXct(format(a,tz="GMT")) a-b unclass(a) unclass(b) unclass(a)-unclass(b) as.numeric(a) as.numeric(b) as.numeric(a)-as.numeric(b) The result on my machine > a=Sys.time() > b<-as.POSIXct(format(a,tz="GMT")) > a-b Time difference of -4.999969 hours > unclass(a) [1] 1203184447 > unclass(b) [1] 1203202447 attr...
2018 Sep 03
0
True length - length(unclass(x)) - without having to call unclass()?
...ing you argumentation, it took me hours to debug a particular problem in one of my internal packages, see https://github.com/Rdatatable/data.table/issues/1281) In the present case, an important and unanswered question is (cited from Henrik): >>> However, I'm concerned that calling unclass(x) may trigger an >>> expensive copy internally in some cases. Is that concern unfounded? If no copy is made, length(unclass(x)) beats length(setattr(..)) in all scenarios. > Doing so > in packages is particularly unhelpful to the whole community - packages > should only u...
2018 Sep 05
4
True length - length(unclass(x)) - without having to call unclass()?
...18 07:55 PM, Henrik Bengtsson wrote: > > Is there a low-level function that returns the length of an object 'x' > > - the length that for instance .subset(x) and .subset2(x) see? An > > obvious candidate would be to use: > > > > .length <- function(x) length(unclass(x)) > > > > However, I'm concerned that calling unclass(x) may trigger an > > expensive copy internally in some cases. Is that concern unfounded? > Unclass() will always copy when "x" is really a variable, because the > value in "x" will be reference...
2018 Sep 03
2
True length - length(unclass(x)) - without having to call unclass()?
...lt;- class(x) > ? # setattr() does not make a copy, but modifies by reference > ? data.table::setattr(x, "class", NULL) > ? # get the length > ? len <- base::length(x) > ? # re-set original classes > ? data.table::setattr(x, "class", cls) > ? # return the unclassed length > ? len > } > > # to check that we do not make unwanted changes > orig_class <- class(x) > > # check that the address in RAM does not change > a1 <- data.table::address(x) > > # 'unclassed' length > stopifnot(.length(x) == 2L) > > # chec...
2005 Apr 07
2
axis colors in pairs plot
The following command produces red axis line in a pairs plot: pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species", pch = "+", col = c("red", "green3", "blue")[unclass(iris$Species)]) Trying to fool pairs in the following way produces the same plot as above: pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species",pch = "+", col = c("black", "red", "green3", "blue")[ 1+ unclass(iris$Species)...
2018 Sep 05
0
True length - length(unclass(x)) - without having to call unclass()?
More generally, I think one of the issues is that R is not yet able to decrement a reference count (or mark a 'shared' data object as 'unshared' after it knows only one binding to it exists). This means passing variables to R closures will mark that object as shared: x <- list() .Internal(inspect(x)) # NAM(1) identity(x) .Internal(inspect(x)) # NAM(3) I think
2005 May 08
3
Light-weight data.frame class: was: how to add method to .Primitive function
...blems I have encountered. As a result I see three issues here: * why "[.default"(x, i) doesn't work if dim(x) is 2? After all a single subscript into a vector works regardless of whether it's a matrix or not. Is there an alternative way to access "[.default"? * why does unclass() make deep copy? This is a facet of the global over-conservatism of R with respect to copying. * is it possible to add some sort copy profiling to R? Something like copyProfiling(TRUE), which should cause R to log sizes of each copied object (just raw sizes w/o any attempt to identify the object)....
2006 Dec 15
1
Switching labels on a factor
Hi All, I'm perplexed by the way the unclass function displays a factor whose labels have been swapped with the relevel function. I realize it won't affect any results and that the relevel did nothing useful in this particular case. I'm just doing it to learn ways to manipulate factors. The display of unclass leaves me feeling that th...
2014 Apr 10
3
Unión de subconjuntos procedentes de bucles
...iables ya están en formato de fecha) le quiero aplicar el siguiente código : conv <- function(data, edad_u=65) { # INICIO DE LA FUNCIÓN # Elimino individuos que tienen una edad_final < edat_u años # ========================================================== data$edad_final <- unclass(round(difftime(data$final, data$nacim, units="auto")/365.25,1)) data <- data[data$edad_final> edad_u,] data$edad_final <- NULL # Elimino provisionalmente la variable edad_final # Con los datos que quedan, distingo 2 situaciones: # 1) La fecha de "origen" es an...