Re: [R] Output multiple sheets to Excel files with openxlsx::write.xlsx

2020-05-27 Thread Enrico Schumann
On Wed, 27 May 2020, John writes: > Hi, > >This is my code a few years ago. I was able to output multiple sheet to > an excel file. Nevertheless, the "append" argument appears to be obsolete. > Now I see only one sheet, the latest added sheet, in the output. Is there > any other way to do it w

Re: [R] Output multiple sheets to Excel files with openxlsx::write.xlsx

2020-05-27 Thread Ivan Calandra
Hi, Rather than creating a workbook as suggested by Enrico, you can simply supply a list to write.xlsx(); each element will be saved in a separate sheet: write.xlsx(list(a = df1, b = df2), file = fl_out) That is not really appending, but that might work for you. HTH, Ivan -- Dr. Ivan Calandra T

Re: [R] Output multiple sheets to Excel files with openxlsx::write.xlsx

2020-05-27 Thread Jeff Newmiller
give the function a list of data frames. On May 26, 2020 11:21:58 PM PDT, John wrote: >Hi, > >This is my code a few years ago. I was able to output multiple sheet to >an excel file. Nevertheless, the "append" argument appears to be >obsolete. >Now I see only one sheet, the latest added sheet, in

[R] Problem in generating an "Orthogonal fractional design"

2020-05-27 Thread Rahul Chakraborty
Dear all, Presently I am working on designing a questionnaire for my discrete choice experiment. I want to generate an orthogonal fractional factorial design for the following problem- The respondent has to choose one out of 4 objects (*X1, X2, X3, X4*). Each of the 4 objects are classified by 10

Re: [R] iterators : checkFunc with ireadLines

2020-05-27 Thread Laurent Rhelp
I installed raku on my PC to test your solution: The command raku -e '.put for lines.grep( / ^^N053 | ^^N163 /, :p );'  Laurents.txt works fine when I write it in the bash command but when I use the pipe command in R as you say there is nothing in lines with lines <- read.table(i) There is t

Re: [R] read_excel() ignore case of worksheet name?

2020-05-27 Thread Ravi Jeyaraman
Ista, With few tweaks this worked beautifully. Thank you so much. -Original Message- From: Ista Zahn [mailto:istaz...@gmail.com] Sent: Tuesday, May 26, 2020 11:38 PM To: Ravi Jeyaraman Cc: Erin Hodgess ; r-help@r-project.org Subject: Re: [R] read_excel() ignore case of worksheet name?

Re: [R] iterators : checkFunc with ireadLines

2020-05-27 Thread Ivan Krylov
On Wed, 27 May 2020 10:56:42 +0200 Laurent Rhelp wrote: > May be it is because I work with MS windows ? That is probably the case. On Windows, pipe() invokes "%COMSPEC% /c ", and the rules of command line quoting are different between POSIX shell and cmd.exe + runtimes of Windows applications [

Re: [R] Problem in generating an "Orthogonal fractional design"

2020-05-27 Thread Bert Gunter
Sorry, Off topic. This list deals with R programming questions, not statistical questions. Try stats.stackexchange.com for those. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" c

[R] struggling with apply

2020-05-27 Thread Michael Ashton
Hi - I have a matrix of n rows and 4 columns. I want to cap the value in each column by a different upper bound. So, suppose my matrix is somematrix <- matrix(c(1,4,3,6,3,9,12,8,5,7,11,11),nrow=3,ncol=4) > somematrix [,1] [,2] [,3] [,4] [1,]16 127 [2,]438 11 [3,

Re: [R] struggling with apply

2020-05-27 Thread Jeff Newmiller
Use the pmin function, not min, for this purpose. On May 27, 2020 10:46:13 AM PDT, Michael Ashton wrote: >Hi - > >I have a matrix of n rows and 4 columns. > >I want to cap the value in each column by a different upper bound. So, >suppose my matrix is > >somematrix <- matrix(c(1,4,3,6,3,9,12,8,5,

Re: [R] struggling with apply

2020-05-27 Thread Rui Barradas
Hello, Try pmin. And loop by column/UB index with sapply/seq_along. sapply(seq_along(UB), function(i) pmin(UB[i], somematrix[,i])) # [,1] [,2] [,3] [,4] #[1,] 1.0 5.5 8.5 7.0 #[2,] 2.5 3.0 8.0 10.5 #[3,] 2.5 5.5 5.0 10.5 Hope this helps, Rui Barradas Às 18:46 de 27/05/20, Mic

Re: [R] struggling with apply

2020-05-27 Thread Michael Ashton
That's it! Thanks. Learn something new every day! Michael Ashton, CFA Managing Principal Enduring Investments LLC W: 973.457.4602 C: 551.655.8006 Schedule a Call: https://calendly.com/m-ashton -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: Wednesday, May 27,

Re: [R] [External] Get a result but an error message as well ?

2020-05-27 Thread varin sacha via R-help
Hi Rui, Richard and other, Many thanks for your responses that solve my problem. Best, SV Le mercredi 20 mai 2020 à 09:09:49 UTC+2, Rui Barradas a écrit : Hello, I get an error but when running colnames(), not mean(). Notes: 1. I have changed the way the residuals are extracted,

Re: [R] [External] struggling with apply

2020-05-27 Thread Richard M. Heiberger
sapply(1:4, FUN=function(i, x, UB=c(2.5, 5.5, 8.5, 10.5)) {result <- x[,i]; result[result > UB[i]] <- UB[i]; result}, x=somematrix) On Wed, May 27, 2020 at 1:46 PM Michael Ashton wrote: > > Hi - > > I have a matrix of n rows and 4 columns. > > I want to cap the value in each column by a different

Re: [R] struggling with apply

2020-05-27 Thread Bert Gunter
Better, I think (no indexing): t(apply(somematrix,1,function(x)pmin(x,UB))) Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, May 27, 2020 at 10:56 AM Rui

Re: [R] struggling with apply

2020-05-27 Thread Michael Ashton
Always amazes me how many ways there are to do these things, none of which I was able to find myself. Thanks! I think the key here was ‘pmin,’ which I didn’t know before. Michael Ashton, CFA Managing Principal Enduring Investments LLC W: 973.457.4602 C: 551.655.8006 Schedule a Call: https://cal

Re: [R] struggling with apply

2020-05-27 Thread Jeff Newmiller
Sigh. Transpose? apply( somematrix, 2, function( x ) pmin( x, UB ) ) On May 27, 2020 11:22:06 AM PDT, Bert Gunter wrote: >Better, I think (no indexing): > >t(apply(somematrix,1,function(x)pmin(x,UB))) > > >Bert Gunter > >"The trouble with having an open mind is that people keep coming along >and

[R] How to fix an error in nonlinear regression

2020-05-27 Thread Vahid Borji
Hello my R friends, I am using the below commands in R: attach(Puromycin) Puromycin plot(Puromycin$conc,Puromycin$rate) mm=function(conc,vmax,k) vmax*conc/(k+conc) mm mm1=nls(rate~mm(conc,vmax,k),data=Puromycin,start=c(vmax=50,k=0.05),subset=state==”treated”) mm1 Unfortunately, I receive the bel

Re: [R] struggling with apply

2020-05-27 Thread Bert Gunter
Jeff: Check it! > somematrix <- matrix(c(1,4,3,6,3,9,12,8,5,7,11,11),nrow=3,ncol=4) > UB=c(2.5, 5.5, 8.5, 10.5) > apply( somematrix, 2, function( x ) pmin( x, UB ) ) [,1] [,2] [,3] [,4] [1,]1 2.5 2.5 2.5 [2,]4 3.0 5.5 5.5 [3,]3 8.5 5.0 8.5 [4,]1 6.0 10.5 7.0 Not wh

Re: [R] Partial matching list elements in R 4.0

2020-05-27 Thread John Harrold
Thankyou Bert and Bill. I have one last question. Is there a tool that will recursively compare two lists to find differences in both their structure and contents? I'm afraid that in the process of converting code from $ to [[]] formats I may inadvertently introduce some errors. And I'd like to Q

Re: [R] Partial matching list elements in R 4.0

2020-05-27 Thread William Dunlap via R-help
all.equal() Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, May 27, 2020 at 1:13 PM John Harrold wrote: > Thankyou Bert and Bill. > > I have one last question. Is there a tool that will recursively compare > two lists to find differences in both their structure and contents? > > I'm afrai

Re: [R] struggling with apply

2020-05-27 Thread Mathew Guilfoyle
A bit quicker: t(pmin(t(somematrix), UB)) > On 27 May 2020, at 20:56, Bert Gunter wrote: > > Jeff: Check it! > >> somematrix <- matrix(c(1,4,3,6,3,9,12,8,5,7,11,11),nrow=3,ncol=4) >> UB=c(2.5, 5.5, 8.5, 10.5) >> apply( somematrix, 2, function( x ) pmin( x, UB ) ) > [,1] [,2] [,3] [,4] >

Re: [R] Partial matching list elements in R 4.0

2020-05-27 Thread John Harrold
Awesome thanks. On Wed, May 27, 2020 at 1:31 PM William Dunlap wrote: > all.equal() > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > > On Wed, May 27, 2020 at 1:13 PM John Harrold > wrote: > >> Thankyou Bert and Bill. >> >> I have one last question. Is there a tool that will recursively

Re: [R] How to fix an error in nonlinear regression

2020-05-27 Thread John Kane
You have subset=state==”treated”). You need to change "treated” to "treated". Tho " " are formatted in your example. On Wed, 27 May 2020 at 15:48, Vahid Borji wrote: > Hello my R friends, > I am using the below commands in R: > > attach(Puromycin) > Puromycin > plot(Puromycin$conc,Puromycin$rate

Re: [R] struggling with apply

2020-05-27 Thread Michael Ashton
This is like "Name that Tune." Can anyone do it in FEWER characters? :-) On May 27, 2020, at 4:32 PM, Mathew Guilfoyle wrote:  A bit quicker: t(pmin(t(somematrix), UB)) On 27 May 2020, at 20:56, Bert Gunter mailto:bgunter.4...@gmail.com>> wrote: Jeff: Check it! somematrix <- matrix(c(1,4

Re: [R] Partial matching list elements in R 4.0

2020-05-27 Thread Bert Gunter
?identical ?rapply might also be useful to get more granular diagnostics. (??) Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, May 27, 2020 at 1:13 PM Joh

Re: [R] How to fix an error in nonlinear regression

2020-05-27 Thread Vahid Borji
Thanks a lot. On Thu, May 28, 2020 at 1:15 AM John Kane wrote: > You have subset=state==”treated”). You need to change "treated” to > "treated". Tho " " are formatted in your example. > > On Wed, 27 May 2020 at 15:48, Vahid Borji wrote: > >> Hello my R friends, >> I am using the below commands

Re: [R] struggling with apply

2020-05-27 Thread Bert Gunter
Yes, that's better --- no looping at the interpreted level. Another version without transposing is: nr <- 3 matrix(pmin(c(somematrix),rep(UB, e = nr)), nrow = nr) Both treat the matrix as a vector stored in column major order. Cheers, Bert On Wed, May 27, 2020 at 1:32 PM Mathew Guilfoyle wro

Re: [R] How to fix an error in nonlinear regression

2020-05-27 Thread Rui Barradas
Hello, This is cross posted [1] which is not well seen. Post and wait for an answer, which you got and are now asking the same, why? Maybe with time other answer will be posted to the first, original, question. [1] https://stackoverflow.com/questions/62051714/how-can-i-fix-an-error-in-nonli

Re: [R] iterators : checkFunc with ireadLines

2020-05-27 Thread William Michels via R-help
Hi Laurent, Off the bat I would have guessed that the problem you're seeing has to do with 'command line quoting' differences between the Windows system and the Linux/Mac systems. I've noticed people using Windows having better command line success with "exterior double-quotes / interior single-qu

[R] Plotting shipment routs on a world map

2020-05-27 Thread Bernard McGarvey
I have used the ggplot2 package to create a world map, the png file of the output is attached. The code I use is below: library(ggplot2) library(mapproj) long_Min <- -180.0 long_Max <- 180.0 lat_Min <- -50.0 lat_Max <- 80.0 Width <- 12.0 Height <- 2.0*Width*(lat_Max-lat_Min)/(long_Max-long_Min) w

[R] Extracting data from list of lists of dataframes

2020-05-27 Thread H
I am a newcomer to R and have been struggling with the following problem: I have a list1(1:N) containing a list2(1:2) each containing dataframes with the same column names but different number of rows. Both lists are named and the rows and the columns in the dataframe are named. I then would lik

Re: [R] Extracting data from list of lists of dataframes

2020-05-27 Thread Bert Gunter
?reproducible example (see posting guide below) or https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example However, I would suggest that you spend some time with an R tutorial or two rather than flailing about with such queries here. R has basic tools -- indexing by

[R] all.equal and use.names

2020-05-27 Thread John Harrold
Howdy Folks, I believe I'm having trouble understanding the documentation for all.equal. If I have two lists like this: t1 = list(a = c(1,2,3), b = c("1", "2", "3")) t2 = list( b = c("1", "2", "3"), a = c(1,2,3)) If I read the documentation correctly, by setting use.names eq

Re: [R] all.equal and use.names

2020-05-27 Thread Bert Gunter
Nope. You misread I think. It says that use.names = TRUE causes mismatches to be **reported** by name rather than index, not that it is recursing by name. It still recurses by component indices. However, I still think that is wrong. It is not reporting mismatches **by** name -- it is reporting mis

Re: [R] all.equal and use.names

2020-05-27 Thread John Harrold
Is there a way to compare t1 and t2 above such that the name is used instead of the index? On Wed, May 27, 2020 at 9:14 PM Bert Gunter wrote: > Nope. You misread I think. It says that use.names = TRUE causes mismatches > to be **reported** by name rather than index, not that it is recursing by >