From jens.oehlschlaegel at truecluster.com  Fri Jun 16 15:03:45 2017
From: jens.oehlschlaegel at truecluster.com (=?UTF-8?Q?=22Jens_Oehlschl=C3=A4gel=22?=)
Date: Fri, 16 Jun 2017 15:03:45 +0200
Subject: [Rd] 'ordered' destroyed to 'factor'
Message-ID: <trinity-35849798-65be-4033-aa6e-d006a5defe16-1497618225192@3capp-webde-bs21>

Dear all,
?
I don't know if you consider this a bug or feature, but it breaks reasonable code: 'unlist' and 'sapply' convert 'ordered' to 'factor' even if all levels are equal. Here is a simple example:

o <- ordered(letters)
o[[1]]
lapply(o, min)[[1]]??????????# ordered factor
unlist(lapply(o, min))[[1]]? # no longer ordered
sapply(o, min)[[1]]??????????# no longer ordered

Jens?Oehlschl?gel
?
?
P.S: The above examples are silly for simple reproduction. The current behavior broke my use-case which had a structure like this
?
# have some data
x <- 1:20
# apply some function to each element
somefunc <- function(x){
? # do something and return an ordinal level
? sample(o, 1)
}
x <- sapply(x, somefunc)
# get minimum result
min(x)
# Error in Summary.factor(c(2L, 26L), na.rm = FALSE) :
#?? ?min? not meaningful for factors
?
?
> version
?????????????? _????????????????????????? ?
platform?????? x86_64-pc-linux-gnu??????? ?
arch?????????? x86_64???????????????????? ?
os???????????? linux-gnu????????????????? ?
system???????? x86_64, linux-gnu????????? ?
status??????????????????????????????????? ?
major????????? 3????????????????????????? ?
minor????????? 4.0??????????????????????? ?
year?????????? 2017?????????????????????? ?
month????????? 04???????????????????????? ?
day??????????? 21???????????????????????? ?
svn rev??????? 72570????????????????????? ?
language?????? R????????????????????????? ?
version.string R version 3.4.0 (2017-04-21)
nickname?????? You Stupid Darkness????????



[Rd] 'ordered' destroyed to 'factor'
=?UTF-8?Q?=22Jens_Oehlschl=C3=A4gel=22?=