[R] Trouble with tibbles
Kevin E. Thorpe
kevin@thorpe @ending from utoronto@c@
Thu Jun 14 15:55:21 CEST 2018
I am trying to learn and use the tidyverse tools and one peculiarity
that I seem to encounter is that converting some data frames to tibbles
gives surprising results. I tried to make a toy example illustrates the
problem but couldn't. Let me show some output that illustrates the problem.
> str(bincrct)
'data.frame': 267 obs. of 4 variables:
$ StudyID : num 20101 20102 20103 20104 20105 ...
$ Intervention: Factor w/ 2 levels "Intervention",..: 2 2 2 2 2 1 1 1
1 1 ...
$ Cluster : num 1 1 1 1 1 2 2 2 2 3 ...
$ apptx : num 0 0 1 0 0 1 1 1 0 1 ...
> as_tibble(bincrct)
Error: `x` must be a numeric or a character vector
> str(as_tibble(bincrct))
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 267 obs. of 4 variables:
$ StudyID : num 20101 20102 20103 20104 20105 ...
$ Intervention: Factor w/ 2 levels "Intervention",..: 2 2 2 2 2 1 1 1
1 1 ...
$ Cluster : num 1 1 1 1 1 2 2 2 2 3 ...
$ apptx : num 0 0 1 0 0 1 1 1 0 1 ...
When I tried to create a data frame and run as_tibble() on it, things
behaved correctly. My best guess is that the old data frame I am using
has some additional baggage with it that I am unaware of.
I also tried manually creating a tibble as follows which also did not work.
> with(bincrct, tibble(StudyID,Intervention,Cluster,apptx))
Error: `x` must be a numeric or a character vector
Any ideas? Here is my sessionInfo(). I just updated my packages this
morning to see if that was the issue.
> sessionInfo()
R version 3.5.0 Patched (2018-04-23 r74633)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Slackware 14.2 x86_64 (post 14.2 -current)
Matrix products: default
BLAS: /usr/local/lib64/R/lib/libRblas.so
LAPACK: /usr/local/lib64/R/lib/libRlapack.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] forcats_0.3.0 stringr_1.3.1 dplyr_0.7.5 purrr_0.2.5
[5] readr_1.1.1 tidyr_0.8.1 tibble_1.4.2 ggplot2_2.2.1
[9] tidyverse_1.2.1 knitr_1.20
loaded via a namespace (and not attached):
[1] Rcpp_0.12.17 cellranger_1.1.0 pillar_1.2.3 compiler_3.5.0
[5] plyr_1.8.4 bindr_0.1.1 tools_3.5.0 lubridate_1.7.4
[9] jsonlite_1.5 nlme_3.1-137 gtable_0.2.0 lattice_0.20-35
[13] pkgconfig_2.0.1 rlang_0.2.1 psych_1.8.4 cli_1.0.0
[17] rstudioapi_0.7 parallel_3.5.0 haven_1.1.1 bindrcpp_0.2.2
[21] xml2_1.2.0 httr_1.3.1 hms_0.4.2 grid_3.5.0
[25] tidyselect_0.2.4 glue_1.2.0 R6_2.2.2 readxl_1.1.0
[29] foreign_0.8-70 modelr_0.1.2 reshape2_1.4.3 magrittr_1.5
[33] scales_0.5.0 rvest_0.3.2 assertthat_0.2.0 mnormt_1.5-5
[37] colorspace_1.3-2 stringi_1.2.3 lazyeval_0.2.1 munsell_0.5.0
[41] broom_0.4.4 crayon_1.3.4
--
Kevin E. Thorpe
Head of Biostatistics, Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's Hospital
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.thorpe using utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016
More information about the R-help
mailing list