Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread William Michels via R-help
Hello Jean-Louis, Noting the subject line of your post I thought the first answer would have been encoding histology stages as factors, and "unclass-ing" them to obtain integers that then can be mathematically manipulated. You can get a lot of work done with all the commands listed on the "factor"

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread Eric Berger
xn <- as.numeric(sub("c",".7",sub("b",".5",sub("a",".3",xc On Sat, Jul 11, 2020 at 5:09 AM Richard O'Keefe wrote: > This can be done very simply because vectors in R can have > named elements, and can be indexed by strings. > > > stage <- c("1" = 1, "1a" = 1.3, "1b" = 1.5, "1c" = 1.7, > +

Re: [R] How to differ stats_cor labels by group on a ggplot

2020-07-10 Thread Jim Lemon
Hi Paulina, Without data it's hard to work out what you are doing. Even a small simulated data set would help to get answers. Jim On Fri, Jul 10, 2020 at 11:49 PM Paulina Skolasinska wrote: > > 'm using ggplot2 to plot two variables at a time. I'm plotting two age groups > and overall data on t

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread Richard O'Keefe
This can be done very simply because vectors in R can have named elements, and can be indexed by strings. > stage <- c("1" = 1, "1a" = 1.3, "1b" = 1.5, "1c" = 1.7, +"2" = 2, "2a" = 2.3, "2b" = 2.5, "2c" = 2.7, +"3" = 3, "3a" = 3.3, "3b" = 3.5, "3c" = 3.7) > testdata <- rep

Re: [R] Bivariate ReLU Distribution

2020-07-10 Thread Abby Spurdle
Last line should use outside = c (0, 1). But not that important. On Sat, Jul 11, 2020 at 1:31 PM Abby Spurdle wrote: > > NOTE: LIMITED TESTING > (You may want to check this carefully, if you're interested in using it). > > library (kubik) > library (mvtnorm) > > sim.cdf <- function (mx, my, sdx,

Re: [R] Bivariate ReLU Distribution

2020-07-10 Thread Abby Spurdle
NOTE: LIMITED TESTING (You may want to check this carefully, if you're interested in using it). library (kubik) library (mvtnorm) sim.cdf <- function (mx, my, sdx, sdy, cor, ..., n=2e5) sim.cdf.2 (mx, my, sdx^2, sdy^2, sdx * sdy * cor, n=n) sim.cdf.2 <- function (mx, my, vx, vy, cov, ..., n=

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread Jean-Louis Abitbol
Many thanks to all. This help-list is wonderful. I have used Rich Heiberger solution using match and found something to learn in each answer. off topic, I also enjoyed very much his 2008 paper on the graphical presentation of safety data Best wishes. On Fri, Jul 10, 2020, at 10:02 PM, F

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread Bert Gunter
Thanks! As I said, cute exercise. Best, Bert On Fri, Jul 10, 2020 at 1:21 PM Fox, John wrote: > Dear Bert, > > Wouldn't you know it, but your contribution arrived just after I pressed > "send" on my last message? So here's how your solution compares: > > > microbenchmark(John = John <- xn[x]

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread Fox, John
Dear Bert, Wouldn't you know it, but your contribution arrived just after I pressed "send" on my last message? So here's how your solution compares: > microbenchmark(John = John <- xn[x], +Rich = Rich <- xn[match(x, xc)], +Jeff = Jeff <- { + n

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread Fox, John
Hi, We've had several solutions, and I was curious about their relative efficiency. Here's a test with a moderately large data vector: > library("microbenchmark") > set.seed(123) # for reproducibility > x <- sample(xc, 1e4, replace=TRUE) # "data" > microbenchmark(John = John <- xn[x], +

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread Bert Gunter
... and continuing with this cute little thread... I found the OP's specification a little imprecise -- are your values always a string that begins with *some sort" of numeric value followed by "some sort" of alpha code? That is, could the numeric value be several digits and the alpha code several

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread David Carlson
Here is a different approach: xc <- c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c") xn <- as.numeric(gsub("a", ".3", gsub("b", ".5", gsub("c", ".7", xc xn # [1] 1.0 1.3 1.5 1.7 2.0 2.3 2.5 2.7 David L Carlson Professor Emeritus of Anthropology Texas A&M University On Fri, Jul 10, 2020 at 1:

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread Jeff Newmiller
Obvious is in the eye of the beholder. Presuming your letters don't go beyond "i": a) Lookup table: tbl <- read.table( text= "OldCode NewCode 1 1 1a1.1 1b1.2 1c1.3 2 2 2a2.1 2b2.2 ", as.is=TRUE, header=TRUE ) tblv <- setNames( tbl$NewCode

Re: [R] [External] Character (1a, 1b) to numeric

2020-07-10 Thread Richard M. Heiberger
> xc <- c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c") > xn <- c(1, 1.3, 1.5, 1.7, 2, 2.3, 2.5, 2.7) > testdata <- rep(c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c"), times=1:8) > testdata [1] "1" "1a" "1a" "1b" "1b" "1b" "1c" "1c" "1c" "1c" "2" "2" "2" "2" "2" [16] "2a" "2a" "2a" "2a" "2a

Re: [R] Character (1a, 1b) to numeric

2020-07-10 Thread Fox, John
Dear Jean-Louis, There must be many ways to do this. Here's one simple way (with no claim of optimality!): > xc <- c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c") > xn <- c(1, 1.3, 1.5, 1.7, 2, 2.3, 2.5, 2.7) > > set.seed(123) # for reproducibility > x <- sample(xc, 20, replace=TRUE) # "data"

[R] Character (1a, 1b) to numeric

2020-07-10 Thread Jean-Louis Abitbol
Dear All I have a character vector, representing histology stages, such as for example: xc <- c("1", "1a", "1b", "1c", "2", "2a", "2b", "2c") and this goes on to 3, 3a etc in various order for each patient. I do have of course a pre-established classification available which does change accor

[R] How to differ stats_cor labels by group on a ggplot

2020-07-10 Thread Paulina Skolasinska
'm using ggplot2 to plot two variables at a time. I'm plotting two age groups and overall data on the same graph. I'm also using stat_cor form the ggpubr package to report correlations for the two groups and overall data. I want each stat_cor label to have a custom subscript - the group name ("o

[R] Bivariate ReLU Distribution

2020-07-10 Thread Arun Kumar Saha via R-help
Hi, I would rather have a Statistics related question hope experts here can provide some suggestions. I have posted this request in some other forum but failed to generate meaningful response I am looking for some technical document on deriving the Distribution function for sum of 2 ReLU(𝑋)=max{

Re: [R] plot shows exponential values incompatible with data

2020-07-10 Thread Fox, John
Dear Jim, As I pointed out yesterday, setting ylim as you suggest still results in "0e+00" as the smallest tick mark, as it should for evenly spaced ticks. Best, John > On Jul 10, 2020, at 12:13 AM, Jim Lemon wrote: > > Hi Luigi, > This is a result of the "pretty" function that calculates h

Re: [R] plot shows exponential values incompatible with data

2020-07-10 Thread Luigi Marongiu
Thank you! I reckon the main problem is the large data range, anyway. I should stick with logarithmic scales... Best regards Luigi On Fri, Jul 10, 2020 at 6:14 AM Jim Lemon wrote: > > Hi Luigi, > This is a result of the "pretty" function that calculates hopefully > good looking axis ticks automat