[R] How to pass a model formula as argument to with.mids
Hello I would like to pass a model formula as an argument to the with.mids function from the mice package. The with.mids functon fits models to multiply imputed data sets. Here's a simple example library(mice) #Create multiple imputations on the nhanes data contained in the mice package. imp - mice(nahnes) #Fitting a linear model with each imputed data set the regular way works fine with(imp, lm(bmi~hyp+chl)) #Creating a formula object and than passing it as argument does not work: form.obj - formula(bmi~hyp+chl) with(imp, lm(form.obj)) #The following doesn't work either expr -lm(bmi~hyp+chl) with(imp, expr) Looking at the definition of with.mids reveals that the second argument is first substituted and than evaluated within each data.frame of the multiply imputed data sets. Is there a way to pass lm(bmi~hyp+chl) without having to change the definition of the with.mids function? Thanks in advance, Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Solved: Input encoding problem when using sweave with xetex
With the kind help of Duncan Murdoch, I finally managed to correctly compile LyX-Sweave documents with XeTeX under Windows. In case someone else is struggling with a similar problem in the future, here is a small summary of what worked for me. I assume that you have already set up Lyx to work with Sweave and XeTeX according to the following instructions: http://cran.r-project.org/contrib/extra/lyx/INSTALL http://wiki.lyx.org/LyX/XeTeX My original problem was that accented letters that were read from Excel-files or other external sources from within R during the LyX-Sweave document compilation were not correctly encoded in UTF-8. However, UTF-8 is needed for typsetting the final document with XeTeX. Because R code chunks contained in the Lyx-Sweave document were executed by running R from the command line, it was necessary to start R with UTF-8 encoding from the command line. I managed to do this by editing the Sweave.sh file which can be found in rhome/bin/ directory. Within sweave.sh, I changed the command echo library(\utils\); Sweave(\file.Rnw\) | R --no-restore --slave into echo library(\utils\); options(encoding=\UTF-8\); Sweave(\file.Rnw\) | R --no-restore --slave Because I wanted to run R with UTF-8 encoding only when I compile my documents with XeTeX and not with LaTeX, I saved the Sweave.sh file with the new name UTF8Sweave.sh in the same directory and changed the definition for the conversion of Lyx-Sweave documents to PDF (xelatex). I did this by defining a new file format in LyX under Tools-Preferences-File handling-File formats. The file format that I defined had the same settings as LaTeX (pdflatex), but I saved it with the new name LaTeX (pdflatexUTF8). I then defined a new converter under Tools-Preferences-File handling-File formats with the following settings: From format: Sweave To format: LaTex (pdflatexUTF8) Converter: R CMD /path/to/UTF8Sweave.sh $$i Because the full path to UTF8Sweave.sh file contained blanks, I had to use the 8.3 filename which I determined by using the MSDOS cmd window. See this post for more information: http://article.gmane.org/gmane.comp.lang.r.general/190040 Finally, I changed the converter LaTeX (pdflatex) - PDF(xelatex) which I had already defined for the original LyX-XeTeX installation(see http://wiki.lyx.org/LyX/XeTeX) to LaTeX (pdflatexUTF8) - PDF(xelatex). I hope this helps. Regards, Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Input encoding problem when using sweave with xetex
Hello Because I want to use different true type fonts with latex, I'm using the XeTeX typesetting engine for my sweave-documents. I'm using Lyx with Sweave on a Windows 7 PC and have set up LyX to work with XeTeX according to the following instructions: http://wiki.lyx.org/LyX/XeTeX Because the input file for XeTeX is assumed to be in UTF-8 encoding, I set the encoding under LyX - Tools - Language Settings - Language to Unicode (XeTeX) (utf8). Accented letters that I write into the LyX-document are correctly typeset in the final PDF-document. However, character strings with accented letters that are read from Excel-files or other sources from within R during the LyX-Sweave document compilation are not. For instance, the German umlauts of the following example are not correctly typeset, when Unicode (XeTeX) (utf8) is used as input encoding. echo=F= require(gdata) x - read.xls(http://www.schwerhoerigkeit.pop.ch/hoergeraete_test.xls;, stringsAsFactors = F)[2,2] x @ I do not have this problem with a Mac computer . I guess, this is because R under Windows does not use UTF-8 encoding. I tried to change the encoding within R by doing the following echo=F= Encoding(x) - 'UTF-8' x @ Unfortunately, this does not work. Does anybody have solution for this problem? Regards, Erich [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Input encoding problem when using sweave with xetex
Thanks. Since the encoding of x is unknown (Encoding(x) gives unknown), I tried iconv(x, , UTF-8) Unfortunately, accented letters are still not printed in the final PDF output. Regards, Erich -Ursprüngliche Nachricht- Von: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Gesendet: Mittwoch, 12. Mai 2010 15:27 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] Input encoding problem when using sweave with xetex On 12/05/2010 8:37 AM, Erich Studerus wrote: Hello Because I want to use different true type fonts with latex, I'm using the XeTeX typesetting engine for my sweave-documents. I'm using Lyx with Sweave on a Windows 7 PC and have set up LyX to work with XeTeX according to the following instructions: http://wiki.lyx.org/LyX/XeTeX Because the input file for XeTeX is assumed to be in UTF-8 encoding, I set the encoding under LyX - Tools - Language Settings - Language to Unicode (XeTeX) (utf8). Accented letters that I write into the LyX-document are correctly typeset in the final PDF-document. However, character strings with accented letters that are read from Excel-files or other sources from within R during the LyX-Sweave document compilation are not. For instance, the German umlauts of the following example are not correctly typeset, when Unicode (XeTeX) (utf8) is used as input encoding. echo=F= require(gdata) x - read.xls(http://www.schwerhoerigkeit.pop.ch/hoergeraete_test.xls;, stringsAsFactors = F)[2,2] x @ I do not have this problem with a Mac computer . I guess, this is because R under Windows does not use UTF-8 encoding. I tried to change the encoding within R by doing the following echo=F= Encoding(x) - 'UTF-8' x @ Unfortunately, this does not work. Does anybody have solution for this problem? You need to use iconv() to change an encoding. What you did just changes the declared encoding, but doesn't actually change any bits. So you'd probably get what you want with x - iconv(x, , UTF-8) x (though you may need to declare the input encoding; it is likely CP1252 on Windows). Duncan Murdoch Regards, Erich [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Input encoding problem when using sweave with xetex
Putting \usepackage[cp1252]{inputenc} into my preamble is not an option, because XeTeX unlike LaTeX needs UTF-8 has input encoding. My goal is also to have a LyX document that can be compiled both on Mac and Windows. I usually compile my Lyx-Sweave documents by one click of a button from within Lyx. R code chunks are therefore executed by calling R from the command line. If anybody knows how to run R with options(encoding=UTF-8) from the command line under windows, that would be helpful. The command that calls R during compilation is contained in this file: http://cran.r-project.org/contrib/extra/lyx/preferences Regards, Erich -Ursprüngliche Nachricht- Von: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Gesendet: Mittwoch, 12. Mai 2010 16:56 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] Input encoding problem when using sweave with xetex On 12/05/2010 9:48 AM, Erich Studerus wrote: Thanks. Since the encoding of x is unknown (Encoding(x) gives unknown), I tried iconv(x, , UTF-8) Unfortunately, accented letters are still not printed in the final PDF output. I think I gave you incomplete advice. The line above will convert the native encoding to UTF-8. That's probably fine, but it's not actually helpful. The problem is that when R outputs a vector, it will convert it back to the native encoding, unless you take action to stop that. If you don't mind changing your document for Windows, you can put \usepackage[cp1252]{inputenc} into the preamble, and use the Windows native CP1252 encoding throughout. If you want something that will work in UTF-8 on Windows, you need to say options(encoding=UTF-8) *before* running Sweave. (If you're running Sweave from the command line using R CMD Sweave then I don't know if you can specify the output encoding; it won't help to do it in the document code chunks). You also need to put the line \usepackage[utf8]{inputenc} into the document preamble, but it sounds as though Lyx has already done that for you. Duncan Murdoch Regards, Erich -Ursprüngliche Nachricht- Von: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Gesendet: Mittwoch, 12. Mai 2010 15:27 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] Input encoding problem when using sweave with xetex On 12/05/2010 8:37 AM, Erich Studerus wrote: Hello Because I want to use different true type fonts with latex, I'm using the XeTeX typesetting engine for my sweave-documents. I'm using Lyx with Sweave on a Windows 7 PC and have set up LyX to work with XeTeX according to the following instructions: http://wiki.lyx.org/LyX/XeTeX Because the input file for XeTeX is assumed to be in UTF-8 encoding, I set the encoding under LyX - Tools - Language Settings - Language to Unicode (XeTeX) (utf8). Accented letters that I write into the LyX-document are correctly typeset in the final PDF-document. However, character strings with accented letters that are read from Excel-files or other sources from within R during the LyX-Sweave document compilation are not. For instance, the German umlauts of the following example are not correctly typeset, when Unicode (XeTeX) (utf8) is used as input encoding. echo=F= require(gdata) x - read.xls(http://www.schwerhoerigkeit.pop.ch/hoergeraete_test.xls;, stringsAsFactors = F)[2,2] x @ I do not have this problem with a Mac computer . I guess, this is because R under Windows does not use UTF-8 encoding. I tried to change the encoding within R by doing the following echo=F= Encoding(x) - 'UTF-8' x @ Unfortunately, this does not work. Does anybody have solution for this problem? You need to use iconv() to change an encoding. What you did just changes the declared encoding, but doesn't actually change any bits. So you'd probably get what you want with x - iconv(x, , UTF-8) x (though you may need to declare the input encoding; it is likely CP1252 on Windows). Duncan Murdoch Regards, Erich [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained
Re: [R] Input encoding problem when using sweave with xetex
Thank you! I edited the Sweave.sh file and it works now for reading data stored as R data files, but the read.xls function from the gdata-package does no longer work. options('encoding'='UTF-8') require(gdata) read.xls(http://www.schwerhoerigkeit.pop.ch/hoergeraete_test.xls;, stringsAsFactors = F)[2,2] This gives NA as output and a warning that there was an invalid entry for the connection. Is there a way to use read.xls with UTF-8 encoding? On Wed, 12 May 2010 12:45:51 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/05/2010 11:36 AM, Erich Studerus wrote: Putting \usepackage[cp1252]{inputenc} into my preamble is not an option, because XeTeX unlike LaTeX needs UTF-8 has input encoding. My goal is also to have a LyX document that can be compiled both on Mac and Windows. I usually compile my Lyx-Sweave documents by one click of a button from within Lyx. R code chunks are therefore executed by calling R from the command line. If anybody knows how to run R with options(encoding=UTF-8) from the command line under windows, that would be helpful. The command that calls R during compilation is contained in this file: http://cran.r-project.org/contrib/extra/lyx/preferences You can do it with a little work. If you look at the rhome/bin/Sweave.sh file, you'll see that R CMD Sweave file.Rnw just executes something like echo library(\utils\); Sweave(\file.Rnw\) | R --no-restore --slave What you want is to execute echo library(\utils\); options(encoding=UTF-8); Sweave(\file.Rnw\) | R --no-restore --slave You could edit the rhome/bin/Sweave.sh file appropriately if you always want Sweave to use UTF-8, or you could edit your Lyx preference file to put in a line like this instead of what it had. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Input encoding problem when using sweave with xetex
Thanks again. Putting options(encoding=) into the R code chunk before calling the read.xls function indeed did the trick. Now, I have one last question: How can I edit the LyX preference file to call R with options(encoding='UTF-8'). I prefer to edit the LyX preference file rather than the Sweave.sh file, because I want to run R with UTF-8 only when I use XeTeX. By editing the LyX preference file, I assume it would be possible to define different R encoding setups for different converters. Erich On Wed, 12 May 2010 14:43:52 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/05/2010 2:29 PM, Erich Studerus wrote: Thank you! I edited the Sweave.sh file and it works now for reading data stored as R data files, but the read.xls function from the gdata-package does no longer work. options('encoding'='UTF-8') require(gdata) read.xls(http://www.schwerhoerigkeit.pop.ch/hoergeraete_test.xls;, stringsAsFactors = F)[2,2] This gives NA as output and a warning that there was an invalid entry for the connection. Is there a way to use read.xls with UTF-8 encoding? I don't know, you'd have to ask its authors. But you can probably set options(encoding=) before calling it. (I'm assuming the read.xls() is in a code chunk in your Sweave file. I would guess that you don't need to set the encoding back to UTF-8 afterwards, but you might: it all depends on when Sweave() opens its output file.) Duncan Murdoch On Wed, 12 May 2010 12:45:51 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/05/2010 11:36 AM, Erich Studerus wrote: Putting \usepackage[cp1252]{inputenc} into my preamble is not an option, because XeTeX unlike LaTeX needs UTF-8 has input encoding. My goal is also to have a LyX document that can be compiled both on Mac and Windows. I usually compile my Lyx-Sweave documents by one click of a button from within Lyx. R code chunks are therefore executed by calling R from the command line. If anybody knows how to run R with options(encoding=UTF-8) from the command line under windows, that would be helpful. The command that calls R during compilation is contained in this file: http://cran.r-project.org/contrib/extra/lyx/preferences You can do it with a little work. If you look at the rhome/bin/Sweave.sh file, you'll see that R CMD Sweave file.Rnw just executes something like echo library(\utils\); Sweave(\file.Rnw\) | R --no-restore --slave What you want is to execute echo library(\utils\); options(encoding=UTF-8); Sweave(\file.Rnw\) | R --no-restore --slave You could edit the rhome/bin/Sweave.sh file appropriately if you always want Sweave to use UTF-8, or you could edit your Lyx preference file to put in a line like this instead of what it had. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Input encoding problem when using sweave with xetex
You were right, that I would run into trouble with all these . However, the second method doesn't work either. Somehow, the UTF8Sweave.sh file is not found during the compilation of my document. It says can't open perl script .../bin/UTF8Sweave.sh: No such file or directory. I double checked that a file with this name is present in the same folder as the original Sweave.sh file and that the Sweave is changed to UTF8Sweave in the LyX preference file. Any idea, what could be wrong? Erich On Wed, 12 May 2010 16:20:03 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/05/2010 3:55 PM, Erich Studerus wrote: Thanks again. Putting options(encoding=) into the R code chunk before calling the read.xls function indeed did the trick. Now, I have one last question: How can I edit the LyX preference file to call R with options(encoding='UTF-8'). I prefer to edit the LyX preference file rather than the Sweave.sh file, because I want to run R with UTF-8 only when I use XeTeX. By editing the LyX preference file, I assume it would be possible to define different R encoding setups for different converters. One way would be to change R CMD Sweave $$i in \converter literate latexR CMD Sweave $$i to echo library(\utils\); options(encoding=\UTF-8\); Sweave(\$$i\) | R --no-restore --slave but you may run into trouble because there's an extra set of to go around there, and I don't know how Lyx handles escaping all those quotes. So probably an easier way to go would be to take the Sweave.sh file that you've already edited, and copy it into UTF8Sweave.sh in the same directory. Then you can change the Lyx preference line to \converter literate latexR CMD UTF8Sweave $$i and things should work. (Then you can restore the original Sweave.sh file for cases where you don't want UTF-8.) Duncan Murdoch Erich On Wed, 12 May 2010 14:43:52 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/05/2010 2:29 PM, Erich Studerus wrote: Thank you! I edited the Sweave.sh file and it works now for reading data stored as R data files, but the read.xls function from the gdata-package does no longer work. options('encoding'='UTF-8') require(gdata) read.xls(http://www.schwerhoerigkeit.pop.ch/hoergeraete_test.xls;, stringsAsFactors = F)[2,2] This gives NA as output and a warning that there was an invalid entry for the connection. Is there a way to use read.xls with UTF-8 encoding? I don't know, you'd have to ask its authors. But you can probably set options(encoding=) before calling it. (I'm assuming the read.xls() is in a code chunk in your Sweave file. I would guess that you don't need to set the encoding back to UTF-8 afterwards, but you might: it all depends on when Sweave() opens its output file.) Duncan Murdoch On Wed, 12 May 2010 12:45:51 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/05/2010 11:36 AM, Erich Studerus wrote: Putting \usepackage[cp1252]{inputenc} into my preamble is not an option, because XeTeX unlike LaTeX needs UTF-8 has input encoding. My goal is also to have a LyX document that can be compiled both on Mac and Windows. I usually compile my Lyx-Sweave documents by one click of a button from within Lyx. R code chunks are therefore executed by calling R from the command line. If anybody knows how to run R with options(encoding=UTF-8) from the command line under windows, that would be helpful. The command that calls R during compilation is contained in this file: http://cran.r-project.org/contrib/extra/lyx/preferences You can do it with a little work. If you look at the rhome/bin/Sweave.sh file, you'll see that R CMD Sweave file.Rnw just executes something like echo library(\utils\); Sweave(\file.Rnw\) | R --no-restore --slave What you want is to execute echo library(\utils\); options(encoding=UTF-8); Sweave(\file.Rnw\) | R --no-restore --slave You could edit the rhome/bin/Sweave.sh file appropriately if you always want Sweave to use UTF-8, or you could edit your Lyx preference file to put in a line like this instead of what it had. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
Re: [R] Input encoding problem when using sweave with xetex
Thanks again. It finally worked after copying the Sweave.sh file to a path that contains no spaces. Is there a special command for windows specific path names with spaces? Erich On Wed, 12 May 2010 18:04:44 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/05/2010 5:12 PM, Erich Studerus wrote: You were right, that I would run into trouble with all these . However, the second method doesn't work either. Somehow, the UTF8Sweave.sh file is not found during the compilation of my document. It says can't open perl script .../bin/UTF8Sweave.sh: No such file or directory. I double checked that a file with this name is present in the same folder as the original Sweave.sh file and that the Sweave is changed to UTF8Sweave in the LyX preference file. Any idea, what could be wrong? Sorry, I forgot that if you make up your own command to be run by R CMD then you need to give the full path to it, and you can't suppress the .sh suffix. So your command should be R CMD /path/to/UTF8Sweave.sh $$i (where /path/to/ is the actual path to where you decide to keep this file, which needn't be in rhome/bin). Duncan Murdoch Erich On Wed, 12 May 2010 16:20:03 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/05/2010 3:55 PM, Erich Studerus wrote: Thanks again. Putting options(encoding=) into the R code chunk before calling the read.xls function indeed did the trick. Now, I have one last question: How can I edit the LyX preference file to call R with options(encoding='UTF-8'). I prefer to edit the LyX preference file rather than the Sweave.sh file, because I want to run R with UTF-8 only when I use XeTeX. By editing the LyX preference file, I assume it would be possible to define different R encoding setups for different converters. One way would be to change R CMD Sweave $$i in \converter literate latexR CMD Sweave $$i to echo library(\utils\); options(encoding=\UTF-8\); Sweave(\$$i\) | R --no-restore --slave but you may run into trouble because there's an extra set of to go around there, and I don't know how Lyx handles escaping all those quotes. So probably an easier way to go would be to take the Sweave.sh file that you've already edited, and copy it into UTF8Sweave.sh in the same directory. Then you can change the Lyx preference line to \converter literate latexR CMD UTF8Sweave $$i and things should work. (Then you can restore the original Sweave.sh file for cases where you don't want UTF-8.) Duncan Murdoch Erich On Wed, 12 May 2010 14:43:52 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/05/2010 2:29 PM, Erich Studerus wrote: Thank you! I edited the Sweave.sh file and it works now for reading data stored as R data files, but the read.xls function from the gdata-package does no longer work. options('encoding'='UTF-8') require(gdata) read.xls(http://www.schwerhoerigkeit.pop.ch/hoergeraete_test.xls;, stringsAsFactors = F)[2,2] This gives NA as output and a warning that there was an invalid entry for the connection. Is there a way to use read.xls with UTF-8 encoding? I don't know, you'd have to ask its authors. But you can probably set options(encoding=) before calling it. (I'm assuming the read.xls() is in a code chunk in your Sweave file. I would guess that you don't need to set the encoding back to UTF-8 afterwards, but you might: it all depends on when Sweave() opens its output file.) Duncan Murdoch On Wed, 12 May 2010 12:45:51 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12/05/2010 11:36 AM, Erich Studerus wrote: Putting \usepackage[cp1252]{inputenc} into my preamble is not an option, because XeTeX unlike LaTeX needs UTF-8 has input encoding. My goal is also to have a LyX document that can be compiled both on Mac and Windows. I usually compile my Lyx-Sweave documents by one click of a button from within Lyx. R code chunks are therefore executed by calling R from the command line. If anybody knows how to run R with options(encoding=UTF-8) from the command line under windows, that would be helpful. The command that calls R during compilation is contained in this file: http://cran.r-project.org/contrib/extra/lyx/preferences You can do it with a little work. If you look at the rhome/bin/Sweave.sh file, you'll see that R CMD Sweave file.Rnw just executes something like echo library(\utils\); Sweave(\file.Rnw\) | R --no-restore --slave What you want is to execute echo library(\utils\); options(encoding=UTF-8); Sweave(\file.Rnw\) | R --no-restore
[R] barchart in lattice 0.18-5
Hello After updating to R version 2.11.0, the xlim argument of the lattice barchart function does no longer work as expected. For example, the following code does not produce the same result in lattice lattice_0.18-3 and lattice_0.18-5 barchart(t(matrix(1:3,1:3)),horizontal=F,box.width=1,xlim=c(0.5,3.5)) In lattice_0.18-3, I could use xlim to remove the spaces between the left y-axis and the first bar and between the right y-axis and the last bar. This is no longer possible in lattice_0.18-5. Is this a bug? Regards, Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] storing initial path for tkgetOpenFile
Hi, I'd like to store the path from which I opened a file with tkgetOpenFile and use it as the initial path for the next function call of tkgetOpenFile. What is the best way of doing this? The following works fine on my Windows computer. However, I'm not sure if it works on other platforms. getFilename - function (filename) { if (missing(filename)) { temp.file - paste(sub(.{10}$, , tempdir()), 'getFilename.tmp', sep = ) if (file.exists(temp.file)) { initialdir - readLines(temp.file, warn = FALSE) } else { initialdir - getwd() } suppressMessages(require(tcltk, quietly = TRUE)) filename - tclvalue(tkgetOpenFile(filetypes = {{All} {.*}}, initialdir = initialdir)) if (!nchar(filename)) { stop('aborted') } if (initialdir != dirname(filename)) { cat (dirname(filename), file = temp.file) } } filename } getFilename() __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Excel Export in a beauty way
Hi, Here's a function to export dataframes to an excel-file with the RDCOMClient package. It makes bold headers and fits the column widths automatically. If more than one dataframe is provided to the function, the dataframes are saved to seperate spreadheets within file. export.xls - function (..., colnames = TRUE, rownames = FALSE) { require(RDCOMClient, quietly = TRUE) y - COMCreate(Excel.Application) wbs - y$Workbooks() wb -wbs$add() shs - wb$Worksheets() export - function(df, sheetname, sheetnr, colnames = colnames, rownames = rownames) { if (!is.data.frame(df)) { df - as.data.frame(df) if (ncol(df) == 1) names(df) - sheetname} cl - sapply(df, function(x) class(x)[1]) dates - which(cl == 'Date') for (i in dates) df[, i] - format(df[,i], '%Y.%m.%d') datetimes - which(cl %in% c('POSIXt', 'POSIXct', 'POSIXlt')) for (i in datetimes) df[, i] - format(df[,i], '%Y.%m.%d %H:%M') numerics - cl == 'numeric' for (i in which(!numerics)) df[, i] - as.character(df[, i]) nas - sapply(df, function(x) any(is.na(x))) missings - which(!numerics nas) for (i in missings) df[is.na(df[, i]), i] - '' sh - shs$Item(sheetnr) sh[['Name']] - sheetname nr - nrow(df) + colnames nc - ncol(df) + rownames cn - dimnames(df)[[2]] rn - dimnames(df)[[1]] startstop - function(x) { l - length(x) stops - starts - rep(NA, l) if (x[1] == TRUE) starts[1] - 1 for (i in seq_along(x)[-1]) { if (x[i] == TRUE x[i-1] == FALSE) starts[i] - i if (x[i] == FALSE x[i-1] == TRUE) stops[i] - i-1 } if (x[l] == TRUE) stops[l] - l rbind(starts = starts[!is.na(starts)], stops = stops[!is.na(stops)]) } startrow - 1+colnames startcol - 1+rownames num - startstop(numerics) num2 - num + rownames for (i in seq_len(ncol(num))) { x - sh$Range(sh$Cells(startrow,num2[1,i]), sh$Cells(nr, num2[2,i])) x[['Value']] - asCOMArray(df[, num[1,i]:num[2,i]]) } notnum - startstop(!numerics) notnum2 - notnum + rownames for (i in seq_len(ncol(notnum))) { x - sh$Range(sh$Cells(startrow, notnum2[1, i]), sh$Cells(nr, notnum2[2, i])) x[['Value']] - asCOMArray(df[,notnum[1,i]:notnum[2,i]]) } missings - which(numerics nas) + rownames for (i in missings) { na - startstop(is.na(df[,i-rownames])) + colnames for (k in seq_len(ncol(na))) { x - sh$Range(sh$Cells(na[1, k] , i), sh$Cells(na[2, k], i)) x[['Value']] - '' } } for (i in (1+rownames):nc) { x - sh$Cells(1,i) if (colnames) { x[['Value']]-cn[i-rownames] Font - x$Font() Font[['Bold']] - TRUE } EntCol -x$EntireColumn() if (i %in% dates) EntCol[['NumberFormat']] - '.MM.TT' if (i %in% datetimes) EntCol[['NumberFormat']] - '.MM.TT hh:mm' EntCol$AutoFit() } if (rownames) { x - sh$Range(sh$Cells(startrow,1),sh$Cells(nr,1)) x[['Value']] - asCOMArray(rn) EntCol -x$EntireColumn() Font - x$Font() Font[['Bold']] - TRUE } } dfn - deparse(substitute(list(...))) df - list(...) dfn - gsub('^list\\(', '', dfn) dfn - gsub('\\)$', '', dfn) dfn - gsub('[ ]', '', dfn) dfn - strsplit(dfn, split = ',')[[1]] dfn - make.names(dfn, unique = TRUE) if (length(df) 2) for (i in seq_len(length(df) - 2)) shs$Add() for (i in seq_len(length(df))) export(df[[i]], sheetname = dfn[i], sheetnr = i, colnames = colnames, rownames = rownames) y[[Visible]] - TRUE } #example: export.xls(iris, mtcars, trees) If you are willing to do the work RDCOMClient or rcom packages give you complete control. See example here: https://stat.ethz.ch/pipermail/r-help/2005-July/075877.html This assumes your platform is Windows and that you have R and Excel on the same machine so that R can control Excel. On Wed, Jun 3, 2009 at 8:29 AM, koj jens.koch at gmx.li wrote: Hallo all, I`ve read a lot of things in this forum about an Excel export via R. It is no problem to export my data frames via write.table or write.xls (xls or csv), but some things are not very convenient for me: I always have to adjust the column with to see all the numbers or the text and there is no frame between the cells. And I missing the possibility to make some headers bold or coloured. I`ve see the output from a Perl-Export and this is a very nice thing, so my question: Is there really no possibility to produce a xls or a xlsx - File with this nice features. Thank you very much in advance, Jens. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Adjusting confidence intervals for paired t-tests of multiple endpoints
Thanks, this comes close to what I need, but the problem is that I have repeated measures in each comparison and SimComp does not seem to handle this. In my experiments, each subject received both placebo and the drug in a randomized order. So, I want to do multiple paired t-test corrected for multiple comparisons. I'm primarily interested in the corrected confidence intervals because I want to plot the mean differences with it. Regards, Erich -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Mark Difford Gesendet: Montag, 2. März 2009 08:34 An: r-help@r-project.org Betreff: Re: [R] Adjusting confidence intervals for pairedt-tests of multiple endpoints Hi Erich, Look at the SimComp package, which handles multiple endpoints, i.e. columns of response variables. Ratio-comparisons are also handled. Good ready-made range of comparisons; you can also set up your own. Regards, Mark. Erich Studerus wrote: Johannes Huesing johan...@huesing.name wrote: Couldn't you re-phrase your model by including timepoint as a continuous regressor and scale as a factor? Well, the measuring time points are 70 170, 300 and 1440 minutes after drug intake. Since the influence of time is cerainly not linear, I think it's better to treat it as categorical factor. In fact, I already calculated mixed effects models with the four-level factor time and the two-level factor treatment and random effects factors subjects (nested in studies) and studies for each scale. I used mixed effects models, because I'm doing a meta-analysis on the raw data of 8 studies. Thus my dataset has not only a grouping structure, but is also unbalanced (not all studies did 4 measurements). I'm not sure, if I could extend my model by including another factor for scale, since these scales measure quite different things. I guess, It would be also very difficult the set up appropriate contrasts to compare each scale on each measuring time point. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Adjusting-confidence-intervals-for-paired-t-tests-of-m ultiple-endpoints-tp22247598p22283385.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Adjusting confidence intervals for paired t-tests of multiple endpoints
Johannes Huesing johan...@huesing.name wrote: Couldn't you re-phrase your model by including timepoint as a continuous regressor and scale as a factor? Well, the measuring time points are 70 170, 300 and 1440 minutes after drug intake. Since the influence of time is cerainly not linear, I think it's better to treat it as categorical factor. In fact, I already calculated mixed effects models with the four-level factor time and the two-level factor treatment and random effects factors subjects (nested in studies) and studies for each scale. I used mixed effects models, because I'm doing a meta-analysis on the raw data of 8 studies. Thus my dataset has not only a grouping structure, but is also unbalanced (not all studies did 4 measurements). I'm not sure, if I could extend my model by including another factor for scale, since these scales measure quite different things. I guess, It would be also very difficult the set up appropriate contrasts to compare each scale on each measuring time point. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Adjusting confidence intervals for paired t-tests of multiple endpoints
Thanks, but as far as I know the multcomp package and the tukeyHSD function can only handle one dependent variable, whereas I have 60 dependent variables. Regards, Erich On Sat, 28 Feb 2009 17:41:11 + (UTC) Dieter Menne dieter.me...@menne-biomed.de wrote: Erich Studerus erich.studerus at bli.uzh.ch writes: Dear R-users, In a randomized placebo-controlled within-subject design, subjects recieved a psycho-active drug and placebo. Subjects filled out a questionnaire containing 15 scales on four different time points after drug administration. In order to detect drug effects on each time point, I compared scale values between placebo and drug for all time conditions and scales, which sums up to 4*15=60 comparisons. Now, I want to adjust the confidence intervals for multiple comparisons. For simple cases, see p.adjust or TukeyHSD (more limited). For complex cases, see simint and friends in package multcomp. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Adjusting confidence intervals for paired t-tests of multiple endpoints
Dear R-users, In a randomized placebo-controlled within-subject design, subjects recieved a psycho-active drug and placebo. Subjects filled out a questionnaire containing 15 scales on four different time points after drug administration. In order to detect drug effects on each time point, I compared scale values between placebo and drug for all time conditions and scales, which sums up to 4*15=60 comparisons. I have summarized the results in a data.frame with columns for t test results including confidence intervals and mean-differences: df1-data.frame(trt=gl(2,35),matrix(rnorm(4200),70,60)) df2-as.data.frame(matrix(NA,60,6)) names(df2)-c('t','df','p','lower','upper','mean.diff') for (i in 1:60) {df2[i,1:6]-as.numeric( unlist(t.test(df1[,i+1]~df1$trt,paired=T))[1:6])} Now, I want to adjust the confidence intervals for multiple comparisons. For a Bonferroni-adjustment, I did the following: df2$std.error.of.diff-df2$mean.diff/df2$t ci-qt(p=1-(0.05/nrow(df2)),df=df2$df)*df2$std.error.of.diff ci.bonf-data.frame(lower=df2$mean.diff-ci,upper=df2$mean.diff+ci) I hope this is the correct method. However, I think, the Bonferroni-adjustment would be much too conservative. I need a less conservative approach, perhaps, something like Holm's method, which I can easily apply to the p-value with p.adjust(df2$p,method='holm'). Is there package, which can do this for the confidence-interval or could someone provide a simple script to calculate this? Thanks a lot! Erich [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problems with impute function from Hmisc library
Hello I would like to use the transcan and impute functions from Hmisc library for single impution. library(Hmisc) m1-data.frame(x1=rnorm(20),x2=rnorm(20),x3=rnorm(20)) m1[c(2,4),1]-NA t1-transcan(~x1+x2+x3,data=m1,imputed=T) impute(t1) Fehler in as.environment(pos) : kein Eintrag names NA im Suchpfad Which means: Error in as.environment(pos): no entry called 'NA' in search path. What am I doing wrong? Regards, Erich [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Two-way repeated measures anova with lme
Dear R-Users, I'm trying to set up a repeated measures anova with two within subjects factors. I tried it by 3 different anova functions: aov, Anova (from car package) and lme (from nlme package). I managed to get the same results with aov and Anova, but the results that I get from lme are slightly different and I don't figure out why. I guess I did not set up the error structure correctly. Here's an example, that I analysed with the 3 different anova functions: set.seed(10) df-data.frame(Time=as.factor(rep(paste('t',1:3,sep=''),each=36)),Cond=as.fa ctor(paste('c',1:4,sep='')),Subj=as.factor(rep(paste('s',1:9,sep=''),each=4) ),y=rnorm(108)) summary(aov(y ~ (Time*Cond) + Error(Subj/(Time*Cond)), data = df)) library(nlme) anova(lme(y~Time*Cond,random=~1|Subj,data=df)) df2-cast(df,Subj~Time+Cond)[-1] mod-lm(cbind(t1_c1,t1_c2,t1_c3,t1_c4,t2_c1,t2_c2,t2_c3,t2_c4,t3_c1,t3_c2,t3 _c3,t3_c4)~1,df2) idata=data.frame(Time=gl(3,4),Cond=gl(4,1)) summary(Anova(mod,idata=idata,idesign=~Time*Cond),multivariate=F) I would highly appreciate if anyone could explain why the results are slightly different. I probably spent hours to find an answer on the internet. I would like to use the lme function, because I need to do multiple comparisons with ghlt function. Regards, Erich [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] diagonal lines in legends of ggplot2
Hi, I have the following problem with ggplot2: When I specify black contours for bars in a barplot, ggplot automatically shows diagonal lines in the legend boxes. Is there a way, to remove these diagonal lines? Here's a simple example: library(ggplot2) df-data.frame(x=gl(6,1),y=rnorm(6,100,50)) ggplot(df,aes(y=y,x=x,fill=x))+geom_bar(aes(group=x),colour='black',size=1)+ scale_fill_brewer(palette='Greys') Thanks for your help! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Several problems with hmisc latex function
Hi, I'm having several problems with the Hmisc latex function. First, there seems to be a conflict between the cellTexCmds and the cgroupTexComds. When I'm using both at the same time, I get an error message. Here's an example. I just added cellTexComds to the example on page 10 of this document: http://biostat.mc.vanderbilt.edu/twiki/pub/Main/StatReport/latexFineControl.pdf x - matrix(1:30, ncol = 5) y - letters[1:6] x - data.frame(x, y) cell.format - matrix(rep(, NCOL(x) * NROW(x)), ncol = NCOL(x)) cell.format[1,1]-bfseries latex(x, file = , cgroup = c(Group A, Group B, Group C), n.cgroup = c(2, 2, 2), rgroup = c(First, Second), n.rgroup = c(4, + 2), colnamesTexCmd = color{green}, cgroupTexCmd = scshape, rgroupTexCmd = bfseries, numeric.dollar = FALSE, title = , ctable = TRUE, label = tab:severalCgroups, caption = More than two column groups.,cellTexCmds=cell.format) I also would like to add more space between the column names and the line above them. With the defaults the column names are extremly close to the line. Adding \\vspace{5mm} works, but adds the space below the names and not on top of the names, where I want to put it. I'm also struggling with the dcolumn option. Can anyone give a reproducible example for this option. I tried x-matrix(c(34.567,3.45,4.5789,345.5),2,2) x-format.df(x,dcolumn=TRUE) latex(x,ctable=T) but it does not work. Thanks for your help! Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NA's in multiple choice summary table in Hmisc
Thank you so much. I have yet another problem that I could not resolve from the documentation. I want to get line breaks for long variable names. Here's an example: Gender-sample(c(m,f),20,replace=TRUE) Education-rnorm(20,13) label(Education)-Years of\nEducation summary(Gender~Education,method=reverse) Descriptive Statistics by Gender Descriptive Statistics by Gender +-+--+--+ | |f |m | | |(N=12)|(N=8) | +-+--+--+ |Years of |12.5/12.9/13.9|12.5/12.9/13.5| |Education| | | +-+--+--+ As you can see, it works fine for the printing in R, but when I submit this table to the latex-function the \n gets removed. How can I prevent this? Regards Erich -Ursprüngliche Nachricht- Von: Frank E Harrell Jr [mailto:[EMAIL PROTECTED] Gesendet: Donnerstag, 9. Oktober 2008 04:17 An: Erich Studerus, Psychiatrische Uni-Klinik Cc: r-help@r-project.org Betreff: Re: [R] NA's in multiple choice summary table in Hmisc Erich Studerus, Psychiatrische Uni-Klinik wrote: Hi, I have a set of 30 binary variables measuring side effects after drug treatment. Since each subject can have multiple side effects, I want to display these side effects in a multiple choice table. I'm using the summary and mChoice functions of the Hmisc package, because it produces nicely formatted latex tables. My problem is, that table includes a category for people who have at least one absent symptom and I don't know how to exclude it. Here's a very easy reproducible example: library(Hmisc) Symptom1-c(Headache,Headache,NA) Symptom2-c(NA,Anxiety,NA) Symptoms-mChoice(Symptom1,Symptom2) summary(~Symptoms,method=reverse) Descriptive Statistics (N=3) +---+---+ | | | +---+---+ |Symptom1 : Headache|67% (2)| +---+---+ |NA |67% (2)| +---+---+ |Anxiety|33% (1)| +---+---+ Now, I want to either completely exclude the NA category or - if included - it should count the number of people who have NA's in all symptoms rather than in a single symptom. In the example above, the NA's should be 1 instead of 2 cases. I tried to specify na.include=FALSE but it does not work. Any help is highly appreciated. Erich Instead of NA put '' or and it should work. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] NA's in multiple choice summary table in Hmisc
Hi, I have a set of 30 binary variables measuring side effects after drug treatment. Since each subject can have multiple side effects, I want to display these side effects in a multiple choice table. I'm using the summary and mChoice functions of the Hmisc package, because it produces nicely formatted latex tables. My problem is, that table includes a category for people who have at least one absent symptom and I don't know how to exclude it. Here's a very easy reproducible example: library(Hmisc) Symptom1-c(Headache,Headache,NA) Symptom2-c(NA,Anxiety,NA) Symptoms-mChoice(Symptom1,Symptom2) summary(~Symptoms,method=reverse) Descriptive Statistics (N=3) +---+---+ | | | +---+---+ |Symptom1 : Headache|67% (2)| +---+---+ |NA |67% (2)| +---+---+ |Anxiety|33% (1)| +---+---+ Now, I want to either completely exclude the NA category or - if included - it should count the number of people who have NA's in all symptoms rather than in a single symptom. In the example above, the NA's should be 1 instead of 2 cases. I tried to specify na.include=FALSE but it does not work. Any help is highly appreciated. Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] getting line breaks with xtable
Sorry, for asking the same question again, but I got no reactions the last time. Maybe it was just overseen by the experts. I'm using the xtable function with Sweave and Lyx and I would like to know how to get automatic line breaks for long strings in a column of the table. I've learned from the Lyx wiki that the Latex command \linebreak produces table cells with multiple lines. I tried to insert \linebreak into the character string, but it didn't work out, because Sweave transforms it automatically to $\backslash$linebreak. Any help is highly appreciated. Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] getting line breaks with xtable
Ok. Sorry, here's a reproducible example: library(xtable) x-as.table(cbind(1:3,rep(this is an example for a long character string that I want break into several lines))) xtable(x) Regards Erich -Ursprüngliche Nachricht- Von: Gabor Grothendieck [mailto:[EMAIL PROTECTED] Gesendet: Freitag, 19. September 2008 15:50 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] getting line breaks with xtable Read the last line to every message to r-help to find out one reason you may be getting no responses. On Fri, Sep 19, 2008 at 9:39 AM, Erich Studerus [EMAIL PROTECTED] wrote: Sorry, for asking the same question again, but I got no reactions the last time. Maybe it was just overseen by the experts. I'm using the xtable function with Sweave and Lyx and I would like to know how to get automatic line breaks for long strings in a column of the table. I've learned from the Lyx wiki that the Latex command \linebreak produces table cells with multiple lines. I tried to insert \linebreak into the character string, but it didn't work out, because Sweave transforms it automatically to $\backslash$linebreak. Any help is highly appreciated. Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to get line breaks with xtable
Hi, I'm using the xtable function with Sweave and Lyx. The table that I'd like to display has very long string characters in one column. Is there a way to get automatic line breaks for the strings in that column with xtable? Thanks for your help! Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plotting group means
Hi all, I want to plot the grouped means of some variables. The dependent variables and the grouping factor are stored in different columns. I want to draw a simple line-plot of means, in which the x-axis represents the variables and y-axis represents the means. The means of the groups should be connected by lines. So far, the only function that I could find comes closest to what I'm looking for, is the error.bars.by-function in the psych-package. To know, what I'm looking for, just type: library(psych) x - matrix(rnorm(500),ncol=20) y - sample(4,25 ,replace=TRUE) x - x+y error.bars.by(x,y,ci=0) Now, I want to put a legend for the grouping factor of this graph. I also would like to manipulate the linetypes and colors of the lines. I've read the documentation, but it was not clear to me, how to do this. Are there other plotting functions in R, which can do the same? Erich Erich Studerus Lic. Phil. Klinische Psychologie Psychiatric University Hospital Zurich Division of Clinical Research Lenggstr. 31 CH-8008 Zurich Switzerland Mail: [EMAIL PROTECTED] Office: +41 44 384 26 66 Mobile: +41 76 563 31 54 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotting group means
Thanks for all the suggestions, but it seems, that all these functions need a rearrangement of my data, since in my case, the dependent variables are in different columns. The error.bars.by-function seems to be the only plotting function, that does not need a rearrangement. Are there other functions, which can do that or is there an easy way to rearrange the columns into one? Thanks Erich -Ursprüngliche Nachricht- Von: hadley wickham [mailto:[EMAIL PROTECTED] Gesendet: Dienstag, 9. September 2008 15:02 An: ONKELINX, Thierry Cc: Erich Studerus; r-help@r-project.org Betreff: Re: [R] plotting group means On Tue, Sep 9, 2008 at 6:56 AM, ONKELINX, Thierry [EMAIL PROTECTED] wrote: Dear Erich, Have a look at ggplot2 library(ggplot2) dataset - expand.grid(x = 1:20, y = factor(LETTERS[1:4]), value = 1:10) dataset$value - rnorm(nrow(dataset), sd = 0.5) + as.numeric(dataset$y) Or with stat_summary: qplot(x, value, data=dataset, colour=y, group = y) + stat_summary(geom=line, fun=mean,size=2) -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to preserve date format while aggregating
Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to preserve date format while aggregating
Thanks, I've already tried that. The problem is, that the original date is not restored when I change the numeric back to date. I get a totally different date. Maybe it has something to do with the original date format. My data are directly imported from a SQL-database. The date column to which I want to apply the aggregate function has the two classes POSIXt and POSIXct. Changing the column to class Date before applying the aggregate function did not help. I still get a different date, when I transform it back to class Date. I would be glad, if someone knew a more elegant way to extract the rows with minimum/earliest date per subject. Erich -Ursprüngliche Nachricht- Von: jim holtman [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 14:24 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Try changing the 'class' of the numeric result back to Date: x - as.Date('2008-09-08') x [1] 2008-09-08 y - as.numeric(x) y [1] 14130 str(y) num 14130 class(y) - Date y [1] 2008-09-08 str(y) Class 'Date' num 14130 On Mon, Sep 8, 2008 at 6:38 AM, Erich Studerus [EMAIL PROTECTED] wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to preserve date format while aggregating
Here's how the dates look like after the sql-query: Oav$Date[1:3] [1] 1991-11-22 00:45:00 CET 1991-12-13 00:01:00 CET 1992-02-06 00:45:00 CET class(oav$Date[1:3]) [1] POSIXt POSIXct x-as.numeric(oav$Date[1:3]) x [1] 690767100 692578860 697333500 class(x)-Date x [1] 3226-01-31 8186-07-07 1204-04-11 I wanteded to apply the aggregate function in R instead of in the SQL-query, because R is much more flexible and faster in manipulating large dataframes. Erich -Ursprüngliche Nachricht- Von: Dr Eberhard Lisse [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 15:43 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Erich, how does the data look, when it comes from SQL? And why not extract the data with SQL directly, so you don't have this issue in the first place? el on 9/8/08 3:15 PM Erich Studerus said the following: Thanks, I've already tried that. The problem is, that the original date is not restored when I change the numeric back to date. I get a totally different date. Maybe it has something to do with the original date format. My data are directly imported from a SQL-database. The date column to which I want to apply the aggregate function has the two classes POSIXt and POSIXct. Changing the column to class Date before applying the aggregate function did not help. I still get a different date, when I transform it back to class Date. I would be glad, if someone knew a more elegant way to extract the rows with minimum/earliest date per subject. Erich -Ursprüngliche Nachricht- Von: jim holtman [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 14:24 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Try changing the 'class' of the numeric result back to Date: x - as.Date('2008-09-08') x [1] 2008-09-08 y - as.numeric(x) y [1] 14130 str(y) num 14130 class(y) - Date y [1] 2008-09-08 str(y) Class 'Date' num 14130 On Mon, Sep 8, 2008 at 6:38 AM, Erich Studerus [EMAIL PROTECTED] wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dr. Eberhard W. Lisse \/ Obstetrician Gynaecologist (Saar) [EMAIL PROTECTED] el108-ARIN / * | Telephone: +264 81 124 6733 (cell) PO Box 8421 \ / Please do NOT email to this address Bachbrecht, Namibia ;/if it is DNS related in ANY way __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.