Open bangecon opened 6 years ago
Can you provide an example? The following works for me.
library(Hmisc)
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
label(group) <- "Treatment Group"
weight <- c(ctl, trt)
summary(lm(weight ~ group))
class(group)
returns [1] "labelled" "factor"
Well, at first I ran your example and it gave me the same error. I figured something must be fishy, so I re-installed Hmisc and re-ran your example. It worked, so I re-ran my example. It also worked. So, there must have been something that didn't update properly when I updated R and my packages. At any rate, fixed now? We'll hope? Thanks for your time attention. Jim
On Wed, May 30, 2018 at 5:48 PM Cole Beck notifications@github.com wrote:
Can you provide an example? The following works for me.
library(Hmisc) ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group <- gl(2, 10, 20, labels = c("Ctl","Trt")) label(group) <- "Treatment Group" weight <- c(ctl, trt) summary(lm(weight ~ group))
class(group) returns [1] "labelled" "factor"
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/harrelfe/Hmisc/issues/93#issuecomment-393344302, or mute the thread https://github.com/notifications/unsubscribe-auth/AQOL2a6-j2SdnUj431-VG_PnMKLAp82zks5t3yHCgaJpZM4UUEBM .
-- James T. Bang, Ph.D. Associate Professor and Chair Department of Economics St. Ambrose University 540-460-5948 (c)
"I was into data before it was big."
Reinstalling and restarting R is always a great place to start. My first thought was that you might have an additional package loaded interfering with behaviour. For instance, the haven package creates a labelled
class that would likely cause problems if loaded after Hmisc.
Here's an example with an Hmisc dataset that was labelled showing the maven problem.
> load("data/pbc.rda")
> head(pbc)
bili albumin stage protime sex fu.days age spiders hepatom ascites alk.phos sgot chol
1 14.5 2.60 4 12.2 female 400 58.76523 present present present 1718.0 137.95 261
2 1.1 4.14 3 10.6 female 4500 56.44627 present present absent 7394.8 113.52 302
3 1.4 3.48 4 12.0 male 1012 70.07255 absent absent absent 516.0 96.10 176
4 1.8 2.54 4 10.3 female 1925 54.74059 present present absent 6121.8 60.63 244
5 3.4 3.53 3 10.9 female 1504 38.10541 present present absent 671.0 113.15 279
6 0.8 3.98 3 11.0 female 2503 66.25873 absent present absent 944.0 93.00 248
trig platelet drug status edema copper
1 172 190 placebo 1 edema despite diuretic therapy 156
2 88 221 placebo 0 no edema 54
3 55 151 placebo 1 edema, no diuretic therapy 210
4 92 183 placebo 1 edema, no diuretic therapy 64
5 72 136 D-penicillamine 0 no edema 143
6 63 NA D-penicillamine 1 no edema 50
> library(haven)
> head(pbc)
Error: `x` and `labels` must be same type
> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] haven_1.1.2
loaded via a namespace (and not attached):
[1] compiler_3.4.4 magrittr_1.5 hms_0.4.2 tools_3.4.4 pillar_1.3.0
[6] rstudioapi_0.7 tibble_1.4.2 crayon_1.3.4 Rcpp_0.12.18 forcats_0.3.0
[11] pkgconfig_2.0.2 rlang_0.2.2
When I updated to R 3.5.0, several lm and glm command lines started giving an error, "Error:
x
must be a numeric or a character vector." Running the same lines in R 3.4.4 did not give that command. I was able to determine that these commands ran fine in R 3.5.0 if I ran them before assigning variable labels using the label() command, but not after assigning the labels. My short run solution is "don't use the labels." But descriptive English labels are nice to have when you have a lot of variables.