Re: [R] Problem with contour(): typo

2020-09-29 Thread Puetz, Benno
As I noted in my earlier post, it does - had checked that ;-) It works by taking corresponding pair fo the input vectors (after possible recycling, as eluded by Helmut in his remark on working on only one vector) as needed for outer. Thanks for the reminder, though, Benno > On 29. Sep

Re: [R] Problem with contour(): typo

2020-09-29 Thread Puetz, Benno
I would assume the following snippet does what you want - note the use of outer with anonymous function wrapping powerTOST: z <- outer(xs, ys, function(x, y)power.TOST(CV = y, theta0 = x, design = "2x2x4", method = "central", n = res[1])) contour(xs, ys, z) Benno > On 29. Sep 2020, at

Re: [R] help to create a simulated dataset

2020-09-29 Thread Bert Gunter
Is this a for a homework assignment? We try to avoid doing others' homework on this list. To learn more about how to do simulations in R, search on "how to simulate data in R" or similar. This brought up many tutorials that should be helpful. If this is not homework, maybe someone else can make s

[R] help to create a simulated dataset

2020-09-29 Thread Peter Wagey
Hi R User, I was trying to create a data matrix with four columns: height, locations (three locations), temperature (three levels) and slope (three classes) and used the following code, but it did not work. I basically wanted to have 20 rows for each class (I have a total of 9 classes). Can you he

Re: [R] 2 KM curves on the same plot

2020-09-29 Thread array chip via R-help
Jim, I tried a few things, I found that clip() works if I just do some regular graphing tasks. But as long as I run lines(fit) with "fit" object is a survfit object, this would reset to default plot region. See the ovarian example below: library(survival) ovarian1<-ovarian ovarian1$fustat[ovari

Re: [R] 2 KM curves on the same plot

2020-09-29 Thread array chip via R-help
Hi Jim, I tried points(-1,-1) before lines() and before clip(), but either way, it still shows everything, :-( It's interesting that the examples with hist() provided by the R help of clip function works nicely. I also tried a simple linear regression plots below, clip() works, too. dat<-data

Re: [R] 2 KM curves on the same plot

2020-09-29 Thread Jim Lemon
Hi John, I should have remembered this. For some reason, the clip() function doesn't operate until you have issued a graphics command. Try: points(-1,-1) before calling lines() Jim On Wed, Sep 30, 2020 at 12:26 PM array chip wrote: > > Hi Jim, > > I tried the clip() function below, surprisingl

Re: [R] 2 KM curves on the same plot

2020-09-29 Thread array chip via R-help
Hi Jim, I tried the clip() function below, surprisingly it did not work! I read the R help file and feel your script should work. To have a workable example, I used the ovarian dataset in the survival package as an example: ovarian1<-ovarian ovarian1$fustat[ovarian$futime>450]<-0 ovarian1$futim

Re: [R] Help with strings

2020-09-29 Thread André Luis Neves
Hi, Sarah, There is a mistake in the column name and the desired output is pretty much the same as the input data frames except for the replacement of 'some_string' by the word 'alcohol' in the column I specified above. Yet, your code is what I am looking for and helped me to get started and figur

Re: [R] Help with strings

2020-09-29 Thread Sarah Goslee
Your desired output seems to be the same as your desired input in your example, and your data frames have different column names. Nonetheless, this bit of code will find rows with "alcohol" in column 3, and for those rows replace the contents of column 4 with column 3. That may not be exactly what

[R] Help with strings

2020-09-29 Thread André Luis Neves
Dear all, I have had difficulties copying the word "alcohol" in the "vehicle" column to replace the string in the column "accident_type". It is a huge list but I have prepared a workable and simple example below and the desired output. I am sure you guys can give me some advice on how to deal wit

Re: [R] how to turn column into column names and fill it with values

2020-09-29 Thread Bert Gunter
A simpler, cleaner, and maybe faster approach is to use outer(): nm <- unique(dat$PLATE) dat <- cbind(dat, 1+outer(dat$PLATE,nm, "==")) names(dat)[-(1:3)] <- nm Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Be

Re: [R] how to turn column into column names and fill it with values

2020-09-29 Thread Rui Barradas
Hello, Sorry, I didn't understand that 1 and 2 are the final values, I thought they would be counts of PLATE. I have changed the auxiliary column 'counts' to 'flag'. mc %>% group_by(PLATE) %>% mutate(flag = 2) %>% pivot_wider( id_cols = c("FID", "IID"), names_from = "PLATE",

Re: [R] how to turn column into column names and fill it with values

2020-09-29 Thread Rui Barradas
Hello, Something like this? mc <- read.table(text = " FID IID PLATE 1 fam0110 G110 4RWG569 2 fam0113 G113 cherry 3 fam0114 G114 cherry 4 fam0117 G117 4RWG569 5 fam0118 G118 5XAV049 6 fam0119 G119 cherry ", header = TRUE) library(dplyr) library(tidyr) mc %>% group_by(PLATE) %>%

Re: [R] how to turn column into column names and fill it with values

2020-09-29 Thread Bert Gunter
You should be able to figure this out yourself! The number of new columns you add **must agree with the number of unique id's PLATE** ! Here is the general approach, slightly more efficient, probably: PL = dat$PLATE nm<- unique(PL) len <- length(nm) m <- matrix(0, ncol = len, nrow = nrow(dat), d

Re: [R] how to turn column into column names and fill it with values

2020-09-29 Thread Ana Marija
oh it seems that I can just use your last line of code and solve my problem: m2=tapply(mc$IID, list(FID=mc$FID, PLATE=mc$PLATE), mean) m2=as.data.frame(m2) library(data.table) m3=setDT(m2, keep.rownames = TRUE)[] colnames(m3)[1] <- "FID" mt=merge(mc,m3,by="FID" for(i in 4:ncol(mt)) mt[,i] <- 1 + (n

Re: [R] how to turn column into column names and fill it with values

2020-09-29 Thread Ana Marija
HI Bert, thank you for getting back to me. I tried this: > dat <- cbind(mc, matrix(0,ncol = 34)) > head(dat) FID IID PLATE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 1 fam0110 G110 4RWG569 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 fam0113 G113 cherry 0 0 0

Re: [R] 2 KM curves on the same plot

2020-09-29 Thread array chip via R-help
Thank you Marc as well! I'll try both ways! Yes this is an oncology study with time set at 5 John On Tuesday, September 29, 2020, 07:08:39 AM PDT, Marc Schwartz wrote: Hi John, >From the looks of the first plot, it would appear that perhaps you are engaged >in a landmark analysis in a

Re: [R] 2 KM curves on the same plot

2020-09-29 Thread array chip via R-help
Thank you very much Jim, this is great!! John On Tuesday, September 29, 2020, 01:35:48 AM PDT, Jim Lemon wrote: Hi John, Perhaps the most direct way would be: plot(fit1, col=1:2) xylim<-par("usr") clip(4,xylim[2],xylim[3],xylim[4]) lines(fit2,col=1:2) Remember that the new clipping rec

Re: [R] how to turn column into column names and fill it with values

2020-09-29 Thread Bert Gunter
I am not sure reshape2 is appropriate for this task, but, assuming I understand correctly, it's quite easy without it. The following is one way, which probably can be done more elegantly and efficiently, but I think it does what you want. "dat" is your example data frame, in which the columns were

[R] how to turn column into column names and fill it with values

2020-09-29 Thread Ana Marija
Hello, I have a data frame like this: > head(mc) FID IID PLATE 1 fam0110 G110 4RWG569 2 fam0113 G113 cherry 3 fam0114 G114 cherry 4 fam0117 G117 4RWG569 5 fam0118 G118 5XAV049 6 fam0119 G119 cherry ... > dim(mc) [1] 16254 > length(unique(mc$PLATE)) [1] 34 I am trying to make a ne

Re: [R] Problem with contour(): typo

2020-09-29 Thread Helmut Schütz
Dear Duncan and Benno, Duncan Murdoch wrote on 2020-09-29 15:21: On 29/09/2020 9:16 a.m., Puetz, Benno wrote: As I noted in my earlier post, it does - had checked that ;-) Great! The result in all of its "beauty": https://forum.bebac.at/mix_entry.php?id=21930#top21939 THX again! Helmut

Re: [R] 2 KM curves on the same plot

2020-09-29 Thread Marc Schwartz via R-help
Hi John, >From the looks of the first plot, it would appear that perhaps you are engaged >in a landmark analysis in an oncology setting, with the landmark time set at 5 >years. On the off chance that you are not familiar with the pros and cons of >that methodology, Google "landmark analysis", w

Re: [R] Problem with contour(): typo

2020-09-29 Thread Duncan Murdoch
On 29/09/2020 9:16 a.m., Puetz, Benno wrote: As I noted in my earlier post, it does - had checked that ;-) Great! Duncan Murdoch It works by taking corresponding pair fo the input vectors (after possible recycling, as eluded by Helmut in his remark on working on only one vector) as needed

Re: [R] Problem with contour(): typo

2020-09-29 Thread Duncan Murdoch
That won't work unless power.TOST is vectorized. outer() will pass it vectors of x and y values. Duncan Murdoch On 29/09/2020 8:11 a.m., Helmut Schütz wrote: Dear Benno, THX, you made my day! Case closed. Helmut Puetz, Benno wrote on 2020-09-29 13:14: I would assume the following snippet

Re: [R] Problem with contour(): typo

2020-09-29 Thread Helmut Schütz
Dear Benno, THX, you made my day! Case closed. Helmut Puetz, Benno wrote on 2020-09-29 13:14: I would assume the following snippet does what you want - note the use of outer with anonymous function wrapping powerTOST: z <- outer(xs, ys, function(x, y)power.TOST(CV = y, theta0 = x, design =

Re: [R] Problem with contour(): typo

2020-09-29 Thread Helmut Schütz
Dear Duncan, Duncan Murdoch wrote on 2020-09-29 11:57: On 29/09/2020 5:37 a.m., Helmut Schütz wrote: Here I'm lost. power.TOST(theta0, CV, ...) vectorizes properly for theta0 _or_ CV but no _both_. Hence library(PowerTOST) power.TOST(theta0 = c(0.9, 0.95, 1), CV = 0.25, n = 28) and power.TOST(t

Re: [R] Problem with contour(): typo

2020-09-29 Thread Duncan Murdoch
On 29/09/2020 5:37 a.m., Helmut Schütz wrote: Dear Duncan, Duncan Murdoch wrote on 2020-09-28 21:47: You're doing a lot of manipulation of the z matrix; I haven't followed all of it, but that's where I'd look for problems.  Generally if you keep your calculation of the z matrix very simple you

Re: [R] Problem with contour(): typo

2020-09-29 Thread Helmut Schütz
Dear Duncan, Duncan Murdoch wrote on 2020-09-28 21:47: You're doing a lot of manipulation of the z matrix; I haven't followed all of it, but that's where I'd look for problems.  Generally if you keep your calculation of the z matrix very simple you are better off. For example, once you have xs

Re: [R] merged data frame with

2020-09-29 Thread Carlos Ortega
Hi All, I recreated a new "sintetic" df1 based on df2 and I could merge: > day_1 <- as.POSIXct("2005-11-14-00-00", format="%Y-%m-%d-%H-%M", tz="Etc/GMT-1") > day_2 <- as.POSIXct("2005-11-14-12-00", format="%Y-%m-%d-%H-%M", tz="Etc/GMT-1") > df2 <- data.frame(data_POSIX=seq(day_1, day_2, by="30 mi

Re: [R] 2 KM curves on the same plot

2020-09-29 Thread Jim Lemon
Hi John, Perhaps the most direct way would be: plot(fit1, col=1:2) xylim<-par("usr") clip(4,xylim[2],xylim[3],xylim[4]) lines(fit2,col=1:2) Remember that the new clipping rectangle will persist until you or something else resets it. Jim On Tue, Sep 29, 2020 at 10:34 AM array chip via R-help wr

Re: [R] merged data frame with

2020-09-29 Thread Ivan Calandra
Hi Stefano, For the merge() part, I'll leave it to more expert users (I rarely use merge(), and every time I need it, it's painful...). To know why instead of NA, check the results with str(df3); I guess it is not the mode you expected. For more details, you should provide the file, or bet

[R] merged data frame with

2020-09-29 Thread Stefano Sofia
Dear R users, I'm struggling with a simple "merge". I have an external file called df.txt like data_POSIX, event 2005-11-14 02:30:00, "start" 2005-11-14 11:30:00, "end" I load it with df1 <- read.table(file="df.txt", header=TRUE, sep=",", dec = ".", stringsAsFactors=FALSE) df1$data_POSIX <- as