hmisc

divide a range of values in bins of equal length: cut vs cut2

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 13:06:49
问题 I'm using the cut function to split my data in equal bins, it does the job but I'm not happy with the way it returns the values. What I need is the center of the bin not the upper and lower ends. I've also tried to use cut2{Hmisc}, this gives me the center of each bins, but it divides the range of data in bins that contains the same numbers of observations, rather than being of the same length. Does anyone have a solution to this? 回答1: It's not too hard to make the breaks and labels yourself,

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : there is no package called 'stringi' [duplicate]

元气小坏坏 提交于 2019-12-18 04:47:05
问题 This question already has answers here : lib unspecified & Error in loadNamespace (4 answers) package 'stringi' does not work after updating to R3.2.1 (6 answers) Closed 2 years ago . When I use library(Hmisc) I get the following error Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : there is no package called 'stringi' Error: package 'ggplot2' could not be loaded As well, if I use library(ggplot2) I get the following error Error in loadNamespace(i, c(lib.loc,

control digits printed by Hmisc::latex on a psych object

徘徊边缘 提交于 2019-12-13 01:47:18
问题 I've produced a comparison of correlation matrices using psych::cortest.mat. I'd like to put the output in a Sweave file for production with knitr. When I use the Hmisc::latex() function, it works, but it also produces about 7 digits for each result, which makes it really unattractive. I could just produce the output with the markup argument within knitr, but all the other tables in my document are more efficiently produced with latex output (results='asis') . Thoughts? #Sample data variable1

Avoiding empty and small groups when using pretty_breaks with cut2

为君一笑 提交于 2019-12-12 03:07:46
问题 I'm working with variables resembling the data val values created below: # data -------------------------------------------------------------------- data("mtcars") val <- c(mtcars$wt, 10.55) I'm cutting this variable in the following manner: # Cuts -------------------------------------------------------------------- cut_breaks <- pretty_breaks(n = 10, eps.correct = 0)(val) res <- cut2(x = val, cuts = cut_breaks) which produces the following results: > table(res) res [ 1, 2) [ 2, 3) [ 3, 4) [

Caption not appearing for LaTeX table when knitting using Hmisc LaTeX Function

我的未来我决定 提交于 2019-12-10 23:59:28
问题 I am trying to create a LaTeX table using the table and Hmisc packages however, I am having trouble getting the caption to appear. Here is a reproducible example: ```{r, results = "asis"} # data: dow <- sample(1:7, 100, replace=TRUE) purp <- sample(1:4, 100, replace=TRUE) dow <- factor(dow, 1:7, c("Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun")) purp <- factor(purp, 1:4, c("Business", "Commute", "Vacation", "Other")) dataframe <- data.frame( dow, purp) # The packages library(tables)

Using cut2 from Hmisc to calculate cuts for different number of groups

懵懂的女人 提交于 2019-12-10 17:22:18
问题 I was trying to calculate equal quantile cuts for a vector by using cut2 from Hmisc. library(Hmisc) c <- c(-4.18304,-3.18343,-2.93237,-2.82836,-2.13478,-2.01892,-1.88773, -1.83124,-1.74953,-1.74858,-0.63265,-0.59626,-0.5681) cut2(c, g=3, onlycuts=TRUE) [1] -4.18304 -2.01892 -1.74858 -0.56810 But I was expecting the following result (33%, 33%, 33%): [1] -4.18304 -2.13478 -1.74858 -0.56810 Should I still use cut2 or try something different? How can I make it work? Thanks for your advice. 回答1:

Error installing Hmisc in R 3.3.0 on centos 6.7

和自甴很熟 提交于 2019-12-08 06:19:37
问题 I have installed R 3.3.0 on a centos 5.2 server, and am trying to install the packages I need to run a shiny app; one of the packages is Hmisc and causing an error. Unfortunately, I have no idea how to proceed. Could someone advise please? Do I need to add additional libraries via yum install ? Many thanks gcc: /builddir/build/BUILD/R-3.3.0/zlib-1.2.8/target/usr/lib64/libz.a: No such file or directory gcc: /builddir/build/BUILD/R-3.3.0/bzip2-1.0.6/target/usr/lib64/libbz2.a: No such file or

Obtaining nice cuts in Hmisc with cut2 (without the [ ) signs )

佐手、 提交于 2019-12-07 13:22:55
问题 I'm currently trying to neatly cut data with use of the Hmisc package, as in the example below: dummy <- data.frame(important_variable=seq(1:1000)) require(Hmisc) dummy$cuts <- cut2(dummy$important_variable, g = 4) The produced cuts are correct with respect to the values: important_variable cuts 1 1 [ 1, 251) 2 2 [ 1, 251) 3 3 [ 1, 251) 4 4 [ 1, 251) 5 5 [ 1, 251) 6 6 [ 1, 251) > table(dummy$cuts) [ 1, 251) [251, 501) [501, 751) [751,1000] 250 250 250 250 However, I would like for the data to

Obtaining nice cuts in Hmisc with cut2 (without the [ ) signs )

牧云@^-^@ 提交于 2019-12-05 19:06:00
I'm currently trying to neatly cut data with use of the Hmisc package, as in the example below: dummy <- data.frame(important_variable=seq(1:1000)) require(Hmisc) dummy$cuts <- cut2(dummy$important_variable, g = 4) The produced cuts are correct with respect to the values: important_variable cuts 1 1 [ 1, 251) 2 2 [ 1, 251) 3 3 [ 1, 251) 4 4 [ 1, 251) 5 5 [ 1, 251) 6 6 [ 1, 251) > table(dummy$cuts) [ 1, 251) [251, 501) [501, 751) [751,1000] 250 250 250 250 However, I would like for the data to be presented slightly differently. For instance instead of [ 1, 251 ) [ 251, 501 ) I would prefer the

data.table: lapply a function with multicolumn output

风格不统一 提交于 2019-12-05 11:03:08
I'm using a function smean.cl.normal from Hmisc package that returns a vector with 3 values: the mean and the lower and upper CI. When I use it on a data.table with 2 groups, I obtain 2 columns and 6 rows. Is there a way to obtain the result with two rows corresponding to 2 groups and separate columns for each of function's outputs, i.e. the mean and CIs? require(Hmisc) require(data.table) dt = data.table(x = rnorm(100), gr = rep(c('A', 'B'), each = 50)) dt[, lapply(.SD, smean.cl.normal), by = gr, .SDcols = "x"] The output: gr x 1: A -0.07916335 2: A -0.33656667 3: A 0.17823998 4: B -0