[R] R 2.12.0 for Windows: error when loading (some) packages
Dear all, I have installed the latest version of R 2.12.0 available on CRAN (http://cran.r-project.org). When I try to load the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' I am running Rgui using C:\R\R-2.12.0\bin\i386\Rgui.exe --vanilla sessionInfo() R version 2.12.0 (2010-10-15) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base By the way, I met the same error when trying to load many contributed packages which were installed in a separate library .libPaths() [1] C:/R/RLIBSC:/R/R-2.12.0/library I had to reinstall them from CRAN. -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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] Error: subscript out of bounds
Dear All I have problem with this: IWJR.temp -IWJR.missing[sample(1:length(IWJR.missing),1),] Error: subscript out of bounds How I can solved this. Thanks IRD __ 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] ncdf installation in R
Sashi Challa wrote: I am trying to install ncdf package on a Linux 64-bit machine. I successfully installed netcdf using this command, ./configure --prefix=/home/challar/netcdf/ --disable-netcdf4 Hi Sashi, Just had a similar issue today. I would suggest the --disable-netcdf4 hasn't been picked up. Try installing an earlier version and using that path instead. See: http://levlafayette.com/node/148 Hope this helps! Lev -- View this message in context: http://r.789695.n4.nabble.com/ncdf-installation-in-R-tp2969252p2999678.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.
Re: [R] rgdal package (Matteo Toro)
The current version of rgdal on CRAN is 0.6-28, not 0.3-5! The latter was never in CRAN, but 0.3-7 dates from 2006. Is your R version (unstated, see the posting guide) also from 2006? On Sun, 17 Oct 2010, ciccp...@libero.it wrote: Hi everybody, I'm trying to install the rgdal package in R, but it seems not possible... i'm typing install.packages(rgdal) Warning in install.packages(rgdal) : argument 'lib' is missing: using '/home/toro/R/i486-pc-linux-gnu-library/2. 9' --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘rgdal’ is not available I also tried to download the package from http://sourceforge. net/projects/rgdal/files/ , and tried $ R CMD INSTALL /home/toro/Downloads/rgdal_0.3-5.tar.gz * Installing to library ‘/home/toro/R/i486-pc-linux-gnu-library/2.9’ * Installing *source* package ‘rgdal’ ... configure: creating ./config.status config.status: creating src/Makevars ** libs g++ -I/usr/share/R/include -I/usr/include/gdal -g -DRGDALDEBUG -fpic -g - O2 -c gdal-bindings.cpp -o gdal-bindings.o gdal-bindings.cpp: In function ‘char* asString(SEXPREC*, int)’: gdal-bindings.cpp:28: error: invalid conversion from ‘const char*’ to ‘char*’ make: *** [gdal-bindings.o] Error 1 ERROR: compilation failed for package ‘rgdal’ * Removing ‘/home/toro/R/i486-pc-linux-gnu-library/2.9/rgdal’ and this happens also for other versions of gdal I have downloaded. The biggest problem is that also other packages like spgrass6, spGDAL and spmaptools are dependent from gdalso i cannot go on Can I ask you to help me , please?? Thank you Matteo __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ 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] R 2.12.0 for Windows: error when loading (some) packages
This is the very first item in the CHANGES file for 2.12.0 How to upgrade your R is an FAQ, http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f On Mon, 18 Oct 2010, Renaud Lancelot wrote: Dear all, I have installed the latest version of R 2.12.0 available on CRAN (http://cran.r-project.org). When I try to load the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' I am running Rgui using C:\R\R-2.12.0\bin\i386\Rgui.exe --vanilla sessionInfo() R version 2.12.0 (2010-10-15) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base By the way, I met the same error when trying to load many contributed packages which were installed in a separate library .libPaths() [1] C:/R/RLIBSC:/R/R-2.12.0/library I had to reinstall them from CRAN. -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ 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] R 2.12.0 for Windows: error when loading (some) packages
Thank you. I have read the CHANGES file as well as the FAQ, indeed. I have uninstalled R, removed the remaining directories and reinstalled the new version. I have also run update.packages(checkBuilt=TRUE, ask=FALSE) Everything works fine except for the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' Did I do something wrong? I'd be interested to know if others met the same problem. 2010/10/18 Prof Brian Ripley rip...@stats.ox.ac.uk: This is the very first item in the CHANGES file for 2.12.0 How to upgrade your R is an FAQ, http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f On Mon, 18 Oct 2010, Renaud Lancelot wrote: Dear all, I have installed the latest version of R 2.12.0 available on CRAN (http://cran.r-project.org). When I try to load the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' I am running Rgui using C:\R\R-2.12.0\bin\i386\Rgui.exe --vanilla sessionInfo() R version 2.12.0 (2010-10-15) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base By the way, I met the same error when trying to load many contributed packages which were installed in a separate library .libPaths() [1] C:/R/RLIBS C:/R/R-2.12.0/library I had to reinstall them from CRAN. -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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] R 2.12.0 for Windows: error when loading (some) packages
I get exactly the same error with package 'RWinEdt' -- though in http://cran.r-project.org/bin/windows/contrib/r-release/ReadMe it is mentioned that this has probably something to do with GUI interactions?? Best, Dimitris On 10/18/2010 8:49 AM, Renaud Lancelot wrote: Thank you. I have read the CHANGES file as well as the FAQ, indeed. I have uninstalled R, removed the remaining directories and reinstalled the new version. I have also run update.packages(checkBuilt=TRUE, ask=FALSE) Everything works fine except for the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' Did I do something wrong? I'd be interested to know if others met the same problem. 2010/10/18 Prof Brian Ripleyrip...@stats.ox.ac.uk: This is the very first item in the CHANGES file for 2.12.0 How to upgrade your R is an FAQ, http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f On Mon, 18 Oct 2010, Renaud Lancelot wrote: Dear all, I have installed the latest version of R 2.12.0 available on CRAN (http://cran.r-project.org). When I try to load the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' I am running Rgui using C:\R\R-2.12.0\bin\i386\Rgui.exe --vanilla sessionInfo() R version 2.12.0 (2010-10-15) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base By the way, I met the same error when trying to load many contributed packages which were installed in a separate library .libPaths() [1] C:/R/RLIBSC:/R/R-2.12.0/library I had to reinstall them from CRAN. -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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] R 2.12.0 for Windows: error when loading (some) packages
On Mon, 18 Oct 2010, Renaud Lancelot wrote: Thank you. I have read the CHANGES file as well as the FAQ, indeed. I have uninstalled R, removed the remaining directories and reinstalled the new version. I have also run update.packages(checkBuilt=TRUE, ask=FALSE) Everything works fine except for the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' Did I do something wrong? I'd be interested to know if others met the same problem. Please locate it -- you have an old copy in your library path and it is not available as a binary for 2.12.0. 2010/10/18 Prof Brian Ripley rip...@stats.ox.ac.uk: This is the very first item in the CHANGES file for 2.12.0 How to upgrade your R is an FAQ, http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f On Mon, 18 Oct 2010, Renaud Lancelot wrote: Dear all, I have installed the latest version of R 2.12.0 available on CRAN (http://cran.r-project.org). When I try to load the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' I am running Rgui using C:\R\R-2.12.0\bin\i386\Rgui.exe --vanilla sessionInfo() R version 2.12.0 (2010-10-15) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base By the way, I met the same error when trying to load many contributed packages which were installed in a separate library .libPaths() [1] C:/R/RLIBS C:/R/R-2.12.0/library I had to reinstall them from CRAN. -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ 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] R 2.12.0 for Windows: error when loading (some) packages
Of course you're right!!! I had a copy of lattice in C:/R/RLIBS .libPaths() [1] C:/R/RLIBSC:/R/R-2.12.0/library I have removed it and this has solved the problem. Thank you very much. 2010/10/18 Prof Brian Ripley rip...@stats.ox.ac.uk: On Mon, 18 Oct 2010, Renaud Lancelot wrote: Thank you. I have read the CHANGES file as well as the FAQ, indeed. I have uninstalled R, removed the remaining directories and reinstalled the new version. I have also run update.packages(checkBuilt=TRUE, ask=FALSE) Everything works fine except for the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' Did I do something wrong? I'd be interested to know if others met the same problem. Please locate it -- you have an old copy in your library path and it is not available as a binary for 2.12.0. 2010/10/18 Prof Brian Ripley rip...@stats.ox.ac.uk: This is the very first item in the CHANGES file for 2.12.0 How to upgrade your R is an FAQ, http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f On Mon, 18 Oct 2010, Renaud Lancelot wrote: Dear all, I have installed the latest version of R 2.12.0 available on CRAN (http://cran.r-project.org). When I try to load the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' I am running Rgui using C:\R\R-2.12.0\bin\i386\Rgui.exe --vanilla sessionInfo() R version 2.12.0 (2010-10-15) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base By the way, I met the same error when trying to load many contributed packages which were installed in a separate library .libPaths() [1] C:/R/RLIBS C:/R/R-2.12.0/library I had to reinstall them from CRAN. -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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 create a dissimilarity object
Thank you, but what about dissimilarity matrix objects? Paul On Thu, Oct 14, 2010 at 5:30 PM, Peter Langfelder peter.langfel...@gmail.com wrote: On Thu, Oct 14, 2010 at 5:21 PM, Paul Rigor (ucla) pr...@ucla.edu wrote: Hi all, I would like to use the fpc and cluster packages for clustering. However, I would like to create a custom dissimilarity object using a library in python. Has anyone attempted or know of a work-around for creating a dissimilarity object from a csv file containing pair-wise distance measures? It is simple. Put the distance matrix into a csv file, read it in as tab = read.csv(...) convert to a distance as dst = as.dist(as.matrix(tab)) then call your favorite clustering method. Here's what as.dist does on a matrix: mat = matrix(c(1:9), 3, 3) mat as.dist(mat) HTH, Peter -- Paul Rigor http://www.ics.uci.edu/~prigor [[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] paste an unevaluated expression
On Mon, Oct 18, 2010 at 3:12 AM, Lorenzo Cattarino l.cattar...@uq.edu.au wrote: Thanks for your reply. However, I have only told you half of the story. My intention was to create a function that outputs 10 different .RData file. These output files need to contain similar command lines (one apply and one save command) but with slightly different arguments. This is what I wrote: Start - 1 End - 120 for (i in 1:10) { object.result - paste('Result', i, sep=) section - paste('apply', '(', 'exp.des[', Start, ':', End, ',], 1, one.row, parms=parameters)') Apply - paste(object.result, section, sep= - ) Save - format(substitute(save(result1, file='/home/uqlcatta/pbs/result1.RData'))) path - '//atlas2/Research/Lorenzo Cattarino/PhD/myR/R_laboratory/' output - paste(path, object.result, sep = ) write(paste(Apply,Save), paste(output, 'R', sep = .)) Start - Start + 120 End - End + 120 } As you can see, apart from an extremely repetitive use of paste, the function works. However there are several problems: 1. I could not find the way to change the arguments of the Save object (e.g. result1 and .../result1.RData for first output file; result2 and .../result2.RData for second output, and so forth) 2. I did not know how to put together the Apply and Save objects in the final command, in a way that resemble two executable lines (each on a different line, and not one behind each other on the same line, like they are now) 3. I was also wondering about a more elegant way to write the function (which looks sort of inefficient to me???). Thanks very much for your help Get rid of the substitute and format and just construct whatever strings you need using paste or sprintf. Use \n for a newline. File names can be constructed the same way. i - 1; Start - 1; End - 100 s - sprintf(Result%d - apply(exp.des[%d:%d,], ...\nMore stuff, i, Start, End) s -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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.
Re: [R] can't find and install reshape2??
Thanks for the ideas, Just wanted to say that it was because I was using an old version of R (as U suggested). I have now updated to v12.0 and I can see and load reshape2. (and I agree with Hadley that it would be nice if there was some way of getting a more informative error message. However thanks to the helpful R community I know now what to do if I have a similar problem in the future) Chris Howden Founding Partner Tricky Solutions Tricky Solutions 4 Tricky Problems Evidence Based Strategic Development, IP development, Data Analysis, Modelling, and Training (mobile) 0410 689 945 (fax / office) (+618) 8952 7878 ch...@trickysolutions.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bernardo Rangel Tura Sent: Tuesday, 12 October 2010 6:53 PM To: r-help Subject: Re: [R] can't find and install reshape2?? On Mon, 2010-10-04 at 10:27 +0930, Chris Howden wrote: Hi everyone, Im trying to install reshape2. But when I click on install package its not coming up!?!?! Im getting reshape, but no reshape2? Ive also tried download.packages(reshape2, destdir=c:\\) download.packages(Reshape2, destdir=c:\\)but no luck!!! Does anyone have any ideas what could be going on? Chris Howden Hi Chris, I have two guess: 1- You don't have installed 'stringr' pakage 2- Your R is outdated Try this two things and after this mail me -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil __ 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] paste an unevaluated expression
Thanks for your reply. However, I have only told you half of the story. My intention was to create a function that outputs 10 different .RData file. These output files need to contain similar command lines (one apply and one save command) but with slightly different arguments. This is what I wrote: Start - 1 End - 120 for (i in 1:10) { object.result - paste('Result', i, sep=) section - paste('apply', '(', 'exp.des[', Start, ':', End, ',], 1, one.row, parms=parameters)') Apply - paste(object.result, section, sep= - ) Save - format(substitute(save(result1, file='/home/uqlcatta/pbs/result1.RData'))) path - '//atlas2/Research/Lorenzo Cattarino/PhD/myR/R_laboratory/' output - paste(path, object.result, sep = ) write(paste(Apply,Save), paste(output, 'R', sep = .)) Start - Start + 120 End - End + 120 } As you can see, apart from an extremely repetitive use of paste, the function works. However there are several problems: 1. I could not find the way to change the arguments of the Save object (e.g. result1 and .../result1.RData for first output file; result2 and .../result2.RData for second output, and so forth) 2. I did not know how to put together the Apply and Save objects in the final command, in a way that resemble two executable lines (each on a different line, and not one behind each other on the same line, like theyare now) 3. I was also wondering about a more elegant way to write the function (which looks sort of inefficient to me???). Thanks very much for your help Lorenzo -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: Monday, 18 October 2010 1:38 PM To: Lorenzo Cattarino Cc: r-help@r-project.org Subject: Re: [R] paste an unevaluated expression On Sun, Oct 17, 2010 at 9:14 PM, Lorenzo Cattarino l.cattar...@uq.edu.au wrote: Hi R-users, I would like to create an expression without evaluating it. Then paste that expression to an object. Example: Result - paste('Result', 1, sep=) paste(Result, substitute(apply(exp.des[1:10,], 1, one.row, parms=parameters)), sep=-) However this pastes EACH element of the unevaluated expression. Instead I just would like the expression to be a character string, with just ONE element. Try this: s - substitute(...whatever...) paste(Result, format(s), sep = -) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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.
Re: [R] function using values separated by a comma
Hi, Thanks again for your help with this. I would like to use a variation of this function in a similar dataset (numeric) with elements separated by a comma e.g. dat - read.table(tc - textConnection( '0,1 1,3 40,10 0,0 20,5 4,2 10,40 10,0 0,11 1,2 120,10 0,0'), sep=) to simply calculate the frequency of the first number divided by the total number, i.e. x[1]/sum(x). to produce: [,1] [,2] [,3] [,4] [1,] 0 0.25 0.8 NaN [2,] 0.8 0.33 0.2 1 [3,] 0 0.33 0.92 NaN My actual dataset is an enormous file (800,000 rows and 100 columns). Any advice on how I can do this, maybe using gsubfn? Thank you very much! -- View this message in context: http://r.789695.n4.nabble.com/function-using-values-separated-by-a-comma-tp2967870p2999723.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] R installation failed on SUSE Linux -- libreadline.so.6 needed
I think that I have successfully installed libreadline.so.6. But still got an error -- libreadline.so.6 needed during R installation on SUSE Linux. help is really appreciated! === # ls -lt /usr/local/lib total 4088 -rw-r--r-- 1 root root 168858 Oct 18 07:15 libhistory.a lrwxrwxrwx 1 root root 15 Oct 18 07:15 libhistory.so - libhistory.so.6 lrwxrwxrwx 1 root root 17 Oct 18 07:15 libhistory.so.6 - libhistory.so.6.0 -r-xr-xr-x 1 root root 110410 Oct 18 07:15 libhistory.so.6.0 -rw-r--r-- 1 root root 1149336 Oct 18 07:15 libreadline.a lrwxrwxrwx 1 root root 16 Oct 18 07:15 libreadline.so - libreadline.so.6 lrwxrwxrwx 1 root root 18 Oct 18 07:15 libreadline.so.6 - libreadline.so.6 .0 -r-xr-xr-x 1 root root 674459 Oct 18 07:15 libreadline.so.6.0 -rw-r--r-- 1 root root 166578 Oct 18 06:43 libhistory.old lrwxrwxrwx 1 root root 17 Oct 18 06:43 libhistory.so.5 - libhistory.so.5.2 -r-xr-xr-x 1 root root 109183 Oct 18 06:43 libhistory.so.5.2 -rw-r--r-- 1 root root 532 Oct 18 06:43 libreadline.old lrwxrwxrwx 1 root root 18 Oct 18 06:43 libreadline.so.5 - libreadline.so.5 .2 -r-xr-xr-x 1 root root 650223 Oct 18 06:43 libreadline.so.5.2 # ls -lt /usr/local/lib64 total 1328 -r-xr-xr-x 1 root root 674459 Oct 18 07:19 libreadline.so.6 -r-xr-xr-x 1 root root 674459 Oct 18 07:19 libreadline.so.6.0 # ldd /usr/local/lib/libreadline.so linux-vdso.so.1 = (0x7fff74957000) libc.so.6 = /lib64/libc.so.6 (0x7f295027f000) /lib64/ld-linux-x86-64.so.2 (0x7f295082b000) # zypper install R-base Retrieving repository 'R10.1-base' metadata [error] Repository 'R10.1-base' is invalid. [|] Repository type can't be determined. Please check if the URIs defined for this repository are pointing to a valid rep ository. Warning: Disabling repository 'R10.1-base' because of the above error. Retrieving repository 'R12.2-base' metadata [error] Repository 'R12.2-base' is invalid. [|] Repository type can't be determined. Please check if the URIs defined for this repository are pointing to a valid rep ository. Warning: Disabling repository 'R12.2-base' because of the above error. Loading repository data... Reading installed packages... Resolving package dependencies... Problem: nothing provides libreadline.so.6 needed by R-patched-2.12.0-3.1.i586 Solution 1: do not ask to install a solvable providing R-base Solution 2: break R-patched by ignoring some of its dependencies Choose from above solutions by number or cancel [1/2/c] (c): -- View this message in context: http://r.789695.n4.nabble.com/R-installation-failed-on-SUSE-Linux-libreadline-so-6-needed-tp2999786p2999786.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.
Re: [R] R 2.12.0 for Windows: error when loading (some) packages
On 18.10.2010 09:01, Dimitris Rizopoulos wrote: I get exactly the same error with package 'RWinEdt' -- though in http://cran.r-project.org/bin/windows/contrib/r-release/ReadMe it is mentioned that this has probably something to do with GUI interactions?? In that case you upgraded R but forgot to update RWinEdt Please run update.packages(checkBuilt=TRUE) and try again. Uwe Ligges Best, Dimitris On 10/18/2010 8:49 AM, Renaud Lancelot wrote: Thank you. I have read the CHANGES file as well as the FAQ, indeed. I have uninstalled R, removed the remaining directories and reinstalled the new version. I have also run update.packages(checkBuilt=TRUE, ask=FALSE) Everything works fine except for the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' Did I do something wrong? I'd be interested to know if others met the same problem. 2010/10/18 Prof Brian Ripleyrip...@stats.ox.ac.uk: This is the very first item in the CHANGES file for 2.12.0 How to upgrade your R is an FAQ, http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f On Mon, 18 Oct 2010, Renaud Lancelot wrote: Dear all, I have installed the latest version of R 2.12.0 available on CRAN (http://cran.r-project.org). When I try to load the recommended package lattice: library(lattice) Error: package 'lattice' is not installed for 'arch=i386' I am running Rgui using C:\R\R-2.12.0\bin\i386\Rgui.exe --vanilla sessionInfo() R version 2.12.0 (2010-10-15) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base By the way, I met the same error when trying to load many contributed packages which were installed in a separate library .libPaths() [1] C:/R/RLIBS C:/R/R-2.12.0/library I had to reinstall them from CRAN. -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 __ 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] R installation failed on SUSE Linux -- libreadline.so.6 needed
On my Suse Box I have ste...@gaia:~ ll /usr/lib/libreadline.* -rw-r--r-- 1 root root 803532 5. Jul 13:46 /usr/lib/libreadline.a lrwxrwxrwx 1 root root 23 16. Jul 09:59 /usr/lib/libreadline.so - /lib/libreadline.so.6.1 So libraries are in /usr/lib, not /usr/local/lib libreadline is provided by ste...@gaia:~ rpm -q --whatprovides libreadline6 libreadline6-6.1-8.1.i586 What Suse version are we talking about? Which repository? Hope that helps already Detlef On Mon, 18 Oct 2010 00:38:41 -0700 (PDT) noclue_ tim@netzero.net wrote: I think that I have successfully installed libreadline.so.6. But still got an error -- libreadline.so.6 needed during R installation on SUSE Linux. help is really appreciated! === # ls -lt /usr/local/lib total 4088 -rw-r--r-- 1 root root 168858 Oct 18 07:15 libhistory.a lrwxrwxrwx 1 root root 15 Oct 18 07:15 libhistory.so - libhistory.so.6 lrwxrwxrwx 1 root root 17 Oct 18 07:15 libhistory.so.6 - libhistory.so.6.0 -r-xr-xr-x 1 root root 110410 Oct 18 07:15 libhistory.so.6.0 -rw-r--r-- 1 root root 1149336 Oct 18 07:15 libreadline.a lrwxrwxrwx 1 root root 16 Oct 18 07:15 libreadline.so - libreadline.so.6 lrwxrwxrwx 1 root root 18 Oct 18 07:15 libreadline.so.6 - libreadline.so.6 .0 -r-xr-xr-x 1 root root 674459 Oct 18 07:15 libreadline.so.6.0 -rw-r--r-- 1 root root 166578 Oct 18 06:43 libhistory.old lrwxrwxrwx 1 root root 17 Oct 18 06:43 libhistory.so.5 - libhistory.so.5.2 -r-xr-xr-x 1 root root 109183 Oct 18 06:43 libhistory.so.5.2 -rw-r--r-- 1 root root 532 Oct 18 06:43 libreadline.old lrwxrwxrwx 1 root root 18 Oct 18 06:43 libreadline.so.5 - libreadline.so.5 .2 -r-xr-xr-x 1 root root 650223 Oct 18 06:43 libreadline.so.5.2 # ls -lt /usr/local/lib64 total 1328 -r-xr-xr-x 1 root root 674459 Oct 18 07:19 libreadline.so.6 -r-xr-xr-x 1 root root 674459 Oct 18 07:19 libreadline.so.6.0 # ldd /usr/local/lib/libreadline.so linux-vdso.so.1 = (0x7fff74957000) libc.so.6 = /lib64/libc.so.6 (0x7f295027f000) /lib64/ld-linux-x86-64.so.2 (0x7f295082b000) # zypper install R-base Retrieving repository 'R10.1-base' metadata [error] Repository 'R10.1-base' is invalid. [|] Repository type can't be determined. Please check if the URIs defined for this repository are pointing to a valid rep ository. Warning: Disabling repository 'R10.1-base' because of the above error. Retrieving repository 'R12.2-base' metadata [error] Repository 'R12.2-base' is invalid. [|] Repository type can't be determined. Please check if the URIs defined for this repository are pointing to a valid rep ository. Warning: Disabling repository 'R12.2-base' because of the above error. Loading repository data... Reading installed packages... Resolving package dependencies... Problem: nothing provides libreadline.so.6 needed by R-patched-2.12.0-3.1.i586 Solution 1: do not ask to install a solvable providing R-base Solution 2: break R-patched by ignoring some of its dependencies Choose from above solutions by number or cancel [1/2/c] (c): -- View this message in context: http://r.789695.n4.nabble.com/R-installation-failed-on-SUSE-Linux-libreadline-so-6-needed-tp2999786p2999786.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] Incorrect positioning of raster images on Windows
I think there's something about the discrete cell versus centre value interpretation here, and you are pushing the pixels through R's graphics engine as well as whatever the png device has to do. I can't enlighten you about the details of that, but by creating an image file more directly with pixels as data you can get the result exactly: test - matrix(c(0, 255), 3, 5) library(rgdal) ## transpose to get orientation right x - image2Grid(list(x = 1:ncol(test), y = 1:nrow(test), z = t(test))) writeGDAL(x, raster.png, driver = PNG, type = Byte) On Mon, Oct 18, 2010 at 3:17 PM, Sharpie ch...@sharpsteen.net wrote: I am working on dumping raster data from R into PNG files using rasterImage(). I am working with a test matrix from the rasterImage() example and using it to produce a PNG image with the following code: # From the example for rasterImage(). A 3 pixel by 5 pixel b/w checkerboard. testImage - as.raster(0:1, nrow=3, ncol=5) testImage [,1] [,2] [,3] [,4] [,5] [1,] #00 #FF #00 #FF #00 [2,] #FF #00 #FF #00 #FF [3,] #00 #FF #00 #FF #00 png('test.png', width=5, height=3, units='px') # Just want the image, no margins, boarders or other fancy stuff. par(mar = c(0,0,0,0) ) plot.new() plotArea = par('fig') rasterImage(testImage, plotArea[1], plotArea[3], plotArea[2], plotArea[4], interpolate = FALSE ) dev.off() However, using R 2.12.0, 64 bit on Windows 7 I have a strange issue where the image is shifted up by one row and to the left by one row. In other words, the bottom row of pixels is missing along with the right column. The code works as I expect it to on OS X and Debian. Am I misusing the plotting commands in some way or should I submit an off-by-one bugreport to Bugzilla? Any suggestions or comments are most welcome. -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://r.789695.n4.nabble.com/Incorrect-positioning-of-raster-images-on-Windows-tp2999649p2999649.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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsum...@gmail.com [[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] read.zoo issues
I am getting problems using read.zoo I have the following data frame head(anlyNiftyDat[,1:10]) TIMESTAMPACC AMBUJACEM AXISBANK BAJAJ-AUTO BHARTIARTL BHEL BPCL CAIRN CIPLA 1 2010-01-04 00:00:00 913.60106.10 992.101732.05 325.20 2426.10 650.75 285.50 337.55 2 2010-01-05 00:00:00 901.75105.30 1012.801740.05 330.35 2435.40 640.95 295.85 331.50 3 2010-01-06 00:00:00 907.60105.95 995.801713.15 326.85 2426.25 631.30 299.45 344.90 4 2010-01-07 00:00:00 913.35105.80 1002.851683.10 329.40 2409.50 619.05 307.85 342.05 5 2010-01-08 00:00:00 912.15105.90 1015.951655.25 325.05 2424.10 629.55 306.15 341.10 6 2010-01-11 00:00:00 915.15106.10 1049.401669.55 328.95 2396.95 627.90 300.15 342.30 class(anlyNiftyDat) [1] cast_dfdata.frame anlyNiftyDatZoo - read.zoo(anlyNiftyDat,split=2,check.names=F) head(anlyNiftyDatZoo[,1:10]) X805.45.1 X805.45.2 X805.45.3 X805.45.4 X805.45.5 X805.45.6 X805.45.7 X805.45.8 X805.45.9 X805.45.10 2010-01-04NANANANANANA NANANA NA 2010-01-05NANANANANANA NANANA NA 2010-01-06NANANANANANA NANANA NA 2010-01-07NANANANANANA NANANA NA 2010-01-08NANANANANANA NANANA NA 2010-01-11NANANANANANA NANANA NA Both the column names and values are thrown off. __ 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] convert factor data to numeric
On Sat, 2010-10-16 at 16:16 -0700, andreas wrote: I had exactly the same problem with trying to import another .csv file. Turns out that I was working on a german computer that instead of using a comma when I saved it as .csv used a semicolon. Just saved it as a normal excel file, put it on a mates computer and saved it as .csv Worked a treat.. I no longer have the earlier messages in this thread, but isn't the above what read.csv2() was designed to overcome? And you could always cook your own with read.table() and specify the separator and decimal for example if neither read.csv nor read.csv2 were exactly what you wanted. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ 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] Unusual Time Series
Dear All, I am not an expert about time series, but I am given a time series to analyze. That time series stands for the list of individuals in contact with a given individual at time t_i, where the ID of every individual is an integer number. (let us not care right now about the meaning of being in contact with in this context, since it does not matter for the discussion). To fix the ideas, consider the following (I am tracking the contacts of an individual whose ID is 1000) c(1000,1100), c(1000,1100,1200),c(1000),c(NA), c(1000,1400) t_1 , t_2 , t_3 , t_4 , t_5 i.e. at time t_i individual 1000 is in contact with individual 1100, at time t_2 he is in contact also with individual 1200, at time t_3 he is by himself (represented as the individual in contact by himself), whereas at time t_4 I have no info about his state (missing info) and finally at time t_5 he is in contact with individual 1400. How would you analyze this series? I do not have a single number at every time so I cannot assume that the series is the typical succession {x_i} at time {t_i}. Replacing the lists of individuals at time t_i with just the number of individuals in contact with individual 1000 at time t_i throws away valuable information (I cannot distinguish any more the situation at time t_1 from that at time t_5). If I use a hash (like those provided by the digest package) I can then squeeze every list at time t_i into a string, but again I lose information (e.g. I cannot tell any more than there is considerable overlap in the situation at time t_1 and t_2). Finally, I would like to stress that strictly speaking I do not have a vector at every time t_i; indeed I do not have an object I can vary continuously (individual 1000 either is in contact with individual 1100 or he is not) and on top of of that I do not have an obvious/uniquely defined notion of distance between the time series at t_i and the one at t_j. Any suggestions are appreciated. Many thanks Lorenzo __ 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] interaction contrasts
hello, yes, thanks a lot - i noticed relevel() beeing very convinient for this purpose. having an authority at hand may i kindly ask, if you could reinsure me that the contrasts below are set up correctly, supposing i want to test the earlier mentioned hypotheses simultanously. thanks, kay Should you need to do it again, you may want to look at the relevel function. I suppose that would meet the definition of some versions of on the fly but once I have a model, rerunning with a different factor leveling is generally pretty painless. -- David. On Oct 15, 2010, at 9:09 AM, Kay Cichini wrote: ..by some (extensive) trial and error reordering the contrast matrix and the reference level i figured it out myself - for anyone who might find this helpful searching for a similar contrast in the future: this should be the right one: c2-rbind(fac2-effect in A=c(0,1,0,0,0,0,0,0), fac2-effect in B=c(0,1,0,0,0,1,0,0), fac2-effect in C=c(0,1,0,0,0,0,1,0), fac2-effect in D=c(0,1,0,0,0,0,0,1), fac2-effect, A*B=c(0,0,0,0,0,1,0,0), fac2-effect, A*C=c(0,0,0,0,0,0,1,0), fac2-effect, A*D=c(0,0,0,0,0,0,0,1), fac2-effect, B*C=c(0,0,0,0,0,-1,1,0), fac2-effect, B*D=c(0,0,0,0,0,-1,0,1), fac2-effect, C*D=c(0,0,0,0,0,0,-1,1)) summary(glht(mod,c2)) Kay Cichini wrote: hello, i was shortly asking the list for help with some interaction contrasts (see below) for which i had to change the reference level of the model on the fly (i read a post that this is possible in multcomp). if someone has a clue how this is coded in multcomp; glht() - please point me there. yours, kay Kay Cichini wrote: hello list, i'd very much appreciate help with setting up the contrast for a 2-factorial crossed design. here is a toy example: library(multcomp) dat-data.frame(fac1=gl(4,8,labels=LETTERS[1:4]), fac2=rep(c(I,II),16),y=rnorm(32,1,1)) mod-lm(y~fac1*fac2,data=dat) ## the contrasts i'm interressted in: c1-rbind(fac2-effect in A=c(0,1,0,0,0,0,0,0), fac2-effect in B=c(0,1,0,0,0,1,0,0), fac2-effect in C=c(0,1,0,0,0,0,1,0), fac2-effect in D=c(0,1,0,0,0,0,0,1), fac2-effect, A*B=c(0,0,0,0,0,1,0,0), fac2-effect, A*C=c(0,0,0,0,0,0,1,0), fac2-effect, A*D=c(0,0,0,0,0,0,0,1)) summary(glht(mod,c1)) ## now i want to add the remaining combinations ## fac2, B*C ## fac2, B*D ## fac2, C*D ## to the simultanous tests to see whether the effects ## of fac2 within the levels of fac1 differ between ## each combination of the levels of fac1, or not ?? thanks for any advise! yours, kay - Kay Cichini Postgraduate student Institute of Botany Univ. of Innsbruck -- View this message in context: http://r.789695.n4.nabble.com/interaction-contrasts-tp2993845p2996987.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.
[R] Mixed Design ANOVA - singular error model
Dear r-help list, I would like to run a mixed design anova to compare the results from one population sample to another. Here my within subject variable (stiulusID) has 45 levels and my between subject variable (group) has two levels. In addition to my number of levels in the within subject variable being very large, one other 'feature' of my data is that it is not balanced on the between subject variable. I have attached a copy of my data for reference. To run the ANOVA, I did this: summary(aov(Result ~ StimulusID * Group + Error(ParticipantToken/(StimulusID + Group)), data = data)) My results were roughly as I had expected, but at the end of the output I have the warning that the model is singular. I have seen this warning listed in other help requests, but from what I saw there this meant that one of my variables was redundant as it was a nesting of the other. I don't think this is the case in my data. Can I trust the results of a Mixed Design ANOVA with the warning? Or indeed with the unbalanced between subject variable? Many thanks for any help for a stats novice. Error: ParticipantToken Df Sum Sq Mean Sq F value Pr(F) Group 1 0.69 0.6934 0.0437 0.8356 Residuals 39 619.47 15.8840 Error: ParticipantToken:StimulusID Df Sum Sq Mean Sq F valuePr(F) StimulusID 44 4607.4 104.713 60.3868 2.2e-16 *** StimulusID:Group 44 170.3 3.870 2.2317 8.106e-06 *** Residuals1716 2975.6 1.734 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Warning message: In aov(Result ~ StimulusID * Group + Error(ParticipantToken/(StimulusID + : Error() model is singular __ 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] Where precision change
Hello everyone. I need some help to understand when number precision in R is set. For this please consider the following example for (i in c(2:length(final))){ sizex - c(sizex,(final[i]-final[i-1],digits=2))) # round is used to remove values that are too small like e-17. print(round(final[i]-final[i-1],digits=2)) } final[2]-final[1] return something like 4.440892e-16, which means that these two numbers are the same. They are two but as they were derived from a different process they are not the same for precision. Also the line print(round(final[2]-final[1]),digits=2) returns 0 which is correct When the above loop stops executing inside sizex variable I find the value 4.440892e-16 which I was not expecting. As you can see from small code snippet before setting the value in the sizex I try to round it. The print gives the right value but for some reason it seems that inside the loop the precision in sizex is changed. Can you please help me clarify that? Best Regards Alex [[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] RODBC Error
Hi Everyone, I am trying to install RODBC but I get the following error message Error in library.dynam(lib, package, package.lib) : shared library 'RODBC' not found In addition: Warning message: package 'RODBC' was built under R version 2.12.0 Error: package/namespace load failed for 'RODBC' I am using R 2.11.0 and I see that the package was built with 2.12.0. However, this has in my experience never been a problem with other packages I have downloaded in the past. A warning gets issued but that is it. Older versions of RODBC are only in the tar.gz and frankly I have no idea how to compile the source code as my IT knowledge is quite limited. Same applies to 2.12.0 for which I couldnt find any .zip file. Any help? Thanks Ron [[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] Directive for first and last array arguments
Hello everyone, could you help me learn if there are any directives that can be used to address the first and last element of a matrix array? I would like to thank you in advance for your help Best Regards Alex [[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] Odp: Where precision change
Hi r-help-boun...@r-project.org napsal dne 18.10.2010 11:58:06: Hello everyone. I need some help to understand when number precision in R is set. For this please consider the following example for (i in c(2:length(final))){ sizex - c(sizex,(final[i]-final[i-1],digits=2))) # round is used to remove values that are too small like e-17. print(round(final[i]-final[i-1],digits=2)) } final[2]-final[1] return something like 4.440892e-16, which means that these two numbers are the same. They are two but as they were derived from a different process they are not the same for precision. Also the line print(round(final[2]-final[1]),digits=2) returns 0 which is correct When the above loop stops executing inside sizex variable I find the value 4.440892e-16 which I was not expecting. As you can see from small code snippet before setting the value in the sizex I try to round it. The print gives the Not having your original data I presume you expect you are rounding when adding to sizex but you are not c(2,((2^0.5)^2,digits=2)) so either you forgot round or you are not telling us the whole story Regards Petr right value but for some reason it seems that inside the loop the precision in sizex is changed. Can you please help me clarify that? Best Regards Alex [[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] Directive for first and last array arguments
X[1,1] .. first x[NROW(x),NCOL(x)] for last element and so on Is this what you need? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alaios Sent: 18 October 2010 15:59 To: Rhelp Subject: [R] Directive for first and last array arguments Hello everyone, could you help me learn if there are any directives that can be used to address the first and last element of a matrix array? I would like to thank you in advance for your help Best Regards Alex [[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] Directive for first and last array arguments
yep. Thanks a lot Best Alex From: Santosh Srinivas santosh.srini...@gmail.com Sent: Mon, October 18, 2010 1:14:26 PM Subject: RE: [R] Directive for first and last array arguments X[1,1] .. first x[NROW(x),NCOL(x)] for last element and so on Is this what you need? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alaios Sent: 18 October 2010 15:59 To: Rhelp Subject: [R] Directive for first and last array arguments Hello everyone, could you help me learn if there are any directives that can be used to address the first and last element of a matrix array? I would like to thank you in advance for your help Best Regards Alex [[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. [[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] Randomly shuffle an array multiple times
Dear List, I have a table i have read into R: NameYes/No John0 Frank 1 Ann 0 James 1 Alex1 etc - 800 different times. What i want to do is shuffle yes/no and randomly re-assign them to the name. I have used sample() and permute(), however there is no way to do this 1000 times. Furthermore, i want to copy the data into a excel spreadsheet in the same order as the data was input so i can build up a distribution of the statistic for each name. When i use shuffle the date gets returned like this - [1] 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1 [34] 0 1 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 [67] 0 0 0 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 [100] 1 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 [133] 0 0 0 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 [166] 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 0 1 [199] 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 [232] 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 [265] 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 [298] 0 1 1 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 0 [331] 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 etc Rather than like this, is there a way to change the output? John0 Frank 1 Ann 0 James 1 Alex1 Can anyone suggest a script that would achieve this? Thanks Peter __ 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] trouble installing R-patched (R-2.12.0) when TMPDIR is specified
On Sun, 17 Oct 2010, Andrew Yee wrote: I noticed that if I specify the location of TMPDIR in .bashrc as follows on a Linux 64 bit system: export TMPDIR=/store/home/ayee/.tmp I get the following error message when installing R 'installing' or making? Looks like the latter. make[3]: Entering directory `/home/ayee/R-patched/src/library/base' building package 'base' make[4]: Entering directory `/home/ayee/R-patched/src/library/base' /bin/sh: line 8: /store/home/ayee/.tmp/R24402: No such file or directory mv: cannot stat `/store/home/ayee/.tmp/R24402': No such file or directory make[4]: *** [mkR] Error 1 make[4]: Leaving directory `/home/ayee/R-patched/src/library/base' make[3]: *** [all] Error 2 make[3]: Leaving directory `/home/ayee/R-patched/src/library/base' make[2]: *** [R] Error 1 make[2]: Leaving directory `/home/ayee/R-patched/src/library' make[1]: *** [R] Error 1 make[1]: Leaving directory `/home/ayee/R-patched/src' make: *** [R] Error 1 [rambo:~/R-patched]$ However, when I don't specify TMPDIR, it installs fine. Any suggestions/comments? Check if /store/home/ayee/.tmp exists and is writeable. I get that message only if it does not. From the manual Ensure that the environment variable TMPDIR is either unset (and /tmp exists and can be written in and scripts can be executed from) or points to a valid temporary directory (one from which execution of scripts is allowed). Thanks, Andrew [[alternative HTML version deleted]] Please do as we ask and not send HTML. __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] read.zoo issues
On Mon, Oct 18, 2010 at 4:24 AM, Santosh Srinivas santosh.srini...@gmail.com wrote: I am getting problems using read.zoo I have the following data frame head(anlyNiftyDat[,1:10]) TIMESTAMP ACC AMBUJACEM AXISBANK BAJAJ-AUTO BHARTIARTL BHEL BPCL CAIRN CIPLA 1 2010-01-04 00:00:00 913.60 106.10 992.10 1732.05 325.20 2426.10 650.75 285.50 337.55 2 2010-01-05 00:00:00 901.75 105.30 1012.80 1740.05 330.35 2435.40 640.95 295.85 331.50 3 2010-01-06 00:00:00 907.60 105.95 995.80 1713.15 326.85 2426.25 631.30 299.45 344.90 4 2010-01-07 00:00:00 913.35 105.80 1002.85 1683.10 329.40 2409.50 619.05 307.85 342.05 5 2010-01-08 00:00:00 912.15 105.90 1015.95 1655.25 325.05 2424.10 629.55 306.15 341.10 6 2010-01-11 00:00:00 915.15 106.10 1049.40 1669.55 328.95 2396.95 627.90 300.15 342.30 class(anlyNiftyDat) [1] cast_df data.frame anlyNiftyDatZoo - read.zoo(anlyNiftyDat,split=2,check.names=F) head(anlyNiftyDatZoo[,1:10]) X805.45.1 X805.45.2 X805.45.3 X805.45.4 X805.45.5 X805.45.6 X805.45.7 X805.45.8 X805.45.9 X805.45.10 2010-01-04 NA NA NA NA NA NA NA NA NA NA 2010-01-05 NA NA NA NA NA NA NA NA NA NA 2010-01-06 NA NA NA NA NA NA NA NA NA NA 2010-01-07 NA NA NA NA NA NA NA NA NA NA 2010-01-08 NA NA NA NA NA NA NA NA NA NA 2010-01-11 NA NA NA NA NA NA NA NA NA NA Both the column names and values are thrown off. There is no reason to think that read.zoo should be able to understand cast_df objects from the reshape package. Use the reshape2 package instead which produces ordinary data frames rather than cast_df objects. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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.
Re: [R] Where precision change
FAQ 7.31 ?all.equal On Mon, Oct 18, 2010 at 5:58 AM, Alaios ala...@yahoo.com wrote: Hello everyone. I need some help to understand when number precision in R is set. For this please consider the following example for (i in c(2:length(final))){ sizex - c(sizex,(final[i]-final[i-1],digits=2))) # round is used to remove values that are too small like e-17. print(round(final[i]-final[i-1],digits=2)) } final[2]-final[1] return something like 4.440892e-16, which means that these two numbers are the same. They are two but as they were derived from a different process they are not the same for precision. Also the line print(round(final[2]-final[1]),digits=2) returns 0 which is correct When the above loop stops executing inside sizex variable I find the value 4.440892e-16 which I was not expecting. As you can see from small code snippet before setting the value in the sizex I try to round it. The print gives the right value but for some reason it seems that inside the loop the precision in sizex is changed. Can you please help me clarify that? Best Regards Alex [[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. -- 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] repeating an analysis
Hi All, For those still interested the code submitted by Phil (see below) worked a treat and produced a vector with the optimal 'nsplit' collated from 50 runs of the rpart model. I then produced a histogram for the vector called answer and chose my modal number for nsplits from which I had my appropriate tree size. many thanks to all who answered Andy On Wed, Oct 13, 2010 at 10:30 AM, Phil Spector spec...@stat.berkeley.eduwrote: Andrew - I think answer = replicate(50,{fit1 - rpart(CHAB~.,data=chabun, method=anova, control=rpart.control(minsplit=10, cp=0.01, xval=10)); x = printcp(fit1); x[which.min(x[,'xerror']),'nsplit']}) will put the numbers you want into answer, but there was no reproducible example to test it on. Unfortunately, I don't know of any way to surpress the printing from printcp(). - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Wed, 13 Oct 2010, Andrew Halford wrote: Hi All, I have to say upfront that I am a complete neophyte when it comes to programming. Nevertheless I enjoy the challenge of using R because of its incredible statistical resources. My problem is this .I am running a regression tree analysis using rpart and I need to run the calculation repeatedly (say n=50 times) to obtain a distribution of results from which I will pick the median one to represent the most parsimonious tree size. Unfortunately rpart does not contain this ability so it will have to be coded for. Could anyone help me with this? I have provided the code (and relevant output) for the analysis I am running. I need to run it n=50 times and from each output pick the appropriate tree size and post it to a datafile where I can then look at the frequency distribution of tree sizes. Here is the code and output from a single run fit1 - rpart(CHAB~.,data=chabun, method=anova, control=rpart.control(minsplit=10, cp=0.01, xval=10)) printcp(fit1) Regression tree: rpart(formula = CHAB ~ ., data = chabun, method = anova, control = rpart.control(minsplit = 10, cp = 0.01, xval = 10)) Variables actually used in tree construction: [1] EXP LAT POC RUG Root node error: 35904/33 = 1088 n= 33 CP nsplit rel error xerrorxstd 1 0.539806 0 1.0 1.0337 0.41238 2 0.050516 1 0.46019 1.2149 0.38787 3 0.016788 2 0.40968 1.2719 0.41280 4 0.010221 3 0.39289 1.1852 0.38300 5 0.01 4 0.38267 1.1740 0.38333 Each time I re-run the model I will get a slightly different output. I want to extract the nsplit number corresponding to the lowest xerror for each run of the model (in this case it is for nsplit = 0) over 50 runs and then look at the distribution of nsplits after 50 runs. Any help appreciated. Andy -- Andrew Halford Associate Researcher Marine Laboratory University of Guam Ph: +1 671 734 2948 [[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. -- Andrew Halford Ph.D Associate Research Scientist Marine Laboratory University of Guam Ph: +1 671 734 2948 [[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] Crossed random effects in lme
Dear all, I am trying to fit a model with crossed random effects using lme. In this experiment, I have been measuring oxygen consumption (mlmin) in bird nestlings, originating from three different treatments (treat), in a respirometer with 7 different channels (ch). I have also measured body mass (mass) for these birds. id nesttreat yearmlmin massch hack 1EP5171117 H 20081.401719138 10.74 2008:17 1EP5170917 H 20081.257163112 9.7 5 2008:17 1EP5171617 H 20081.050170714 10.26 2008:17 1EP5171217 H 20081.330495314 9.6 7 2008:17 1EP51791687 M 20081.07625708 9.7 3 2008:687 1EP51772823 H 20081.336820232 10.24 2008:823 1EP51778613 L 20081.300814516 10.75 2008:613 1EP52336207 M 20081.071775936 10.73 2008:207 1EP52403808 H 20081.142389688 10.35 2008:808 1ER17603838 M 20090.984225217 9.6 3 2009:838 1ER17607838 M 20091.045058894 9.3 4 2009:838 1ER17600247 L 20091.047603048 9.2 5 2009:247 1ER17299247 L 20090.974569658 9.2 6 2009:247 1ER17292617 H 20091.271260094 10.57 2009:617 1ER172067009M 20091.074791644 10.72 2009:7009 1ER17221730 H 20091.423266177 10.24 2009:730 1ER17275863 L 20091.433076022 10.74 2009:863 1ER17277863 L 20091.165236024 9.7 5 2009:863 1ER17283863 L 20091.139311895 10.46 2009:863 1ER17280863 L 20091.056161196 10.47 2009:863 CK59991 690 H 20100.994878996 9.5 2 2010:690 CK59806 161 M 20101.070052025 9.7 6 2010:161 CK59859 545 M 20101.456680579 9.9 4 2010:545 CK59862 545 M 20101.350698793 9.9 5 2010:545 CK59871 223 L 20100.830582186 8.3 6 2010:223 CK59868 223 L 20100.776241825 8 7 2010:223 CL77343 365 M 20101.352454484 10.34 2010:365 CL77338 365 M 20101.327691628 9.6 5 2010:365 CL77356 191 H 20101.212796979 11.31 2010:191 CL77361 191 H 20100.882307732 11.42 2010:191 CL77355 191 H 20101.137097586 10.93 2010:191 I want to include both nesting attempt (hack) and respirometer channel (ch) as random factors in a model trying to explain variation in oxygen consumption. From Pinheiro Bates (2000), I've gathered that this model could be fit making use of pdBlocked and pdIdent, so I've tried fitting the below model: m1.bmr-with(bmred.df,lme(mlmin~treat*year+massout,random=pdBlocked(list(pdIdent(~hack-1),pdIdent(~ch-1))) )) However, my model fails with the following error message: Error in getGroups.data.frame(dataMix, groups) : Invalid formula for groups I would much appreciate any input on this! Kind regards, Andreas Nord Sweden -- View this message in context: http://r.789695.n4.nabble.com/Crossed-random-effects-in-lme-tp3000101p3000101.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] Looking for covariance function -OR- how do you search
Hello everyone., I am looking for a covariance function this not the first time I have this type of problem (to find which function does something). I try in google with R cran covariance function but usually this ends with different results that do not help me that much. Could you please try to advice me how to search for what function implements the functionality you want. Best Regards Alex [[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] Looking for covariance function -OR- how do you search
Hi Alex, There are a couple ways. You can install the SOS package, which has some nice search features. You can also use R's built in RSiteSearch(some relevant keywords), also, if you think you are close to what the function should be called, you can try: apropos(cov) [1] ability.cov cov cov2cor covratiocov.wt [6] discoveries recover vcov which turns up functions with your search term in them. To answer your question about the function, see ?cov . Cheers, Josh On Mon, Oct 18, 2010 at 5:26 AM, Alaios ala...@yahoo.com wrote: Hello everyone., I am looking for a covariance function this not the first time I have this type of problem (to find which function does something). I try in google with R cran covariance function but usually this ends with different results that do not help me that much. Could you please try to advice me how to search for what function implements the functionality you want. Best Regards Alex [[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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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] Randomly shuffle an array 1000 times
Dear List, I have a table i have read into R: NameYes/No John0 Frank 1 Ann 0 James 1 Alex1 etc - 800 different times. What i want to do is shuffle yes/no and randomly re-assign them to the name. I have used sample() and permute(), however there is no way to do this 1000 times. Furthermore, i want to copy the data into a excel spreadsheet in the same order as the data was input so i can build up a distribution of the statistic for each name. When i use shuffle the date gets returned like this - [1] 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1 [34] 0 1 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 [67] 0 0 0 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 [100] 1 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 [133] 0 0 0 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 [166] 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 0 1 [199] 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 [232] 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 [265] 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 [298] 0 1 1 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 0 [331] 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 etc Rather than like this John0 Frank 1 Ann 0 James 1 Alex1 Can anyone suggest a script that would achieve this? Thanks Peter __ 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] rgdal package (Matteo Toro)
For clarification, the OP downloaded files published before rgdal was available on CRAN from the deprecated sourceforge site. The OPs references to the other early development packages (from roughly 5 years ago) are also from sourceforge. The rgdal and r-spatial projects on sourceforge explicitly refer any potential downloaders to CRAN. Of course, CVS users can access r-spatial project modules on sourceforge, but the package tarballs remain for archive purposes only. Indeed, rgdal is now hosted on R-Forge, not sourceforge. Even if the OP came through the link to rgdal on sourceforge on the gdal.org site, this states clearly that: The R contributed package rgdal is available from CRAN as a source package for installation on platforms with the full build train and external dependencies. The external dependencies are GDAL and its dependencies. These may also be provided in binary form for some platforms, but to install the source rgdal package, the headers and development libraries will be required. ... This site is only used for development, not for releasing software. Roger Prof Brian Ripley wrote: The current version of rgdal on CRAN is 0.6-28, not 0.3-5! The latter was never in CRAN, but 0.3-7 dates from 2006. Is your R version (unstated, see the posting guide) also from 2006? On Sun, 17 Oct 2010, ciccp...@libero.it wrote: Hi everybody, I'm trying to install the rgdal package in R, but it seems not possible... i'm typing install.packages(rgdal) Warning in install.packages(rgdal) : argument 'lib' is missing: using '/home/toro/R/i486-pc-linux-gnu-library/2. 9' --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘rgdal’ is not available I also tried to download the package from http://sourceforge. net/projects/rgdal/files/ , and tried $ R CMD INSTALL /home/toro/Downloads/rgdal_0.3-5.tar.gz * Installing to library ‘/home/toro/R/i486-pc-linux-gnu-library/2.9’ * Installing *source* package ‘rgdal’ ... configure: creating ./config.status config.status: creating src/Makevars ** libs g++ -I/usr/share/R/include -I/usr/include/gdal -g -DRGDALDEBUG -fpic -g - O2 -c gdal-bindings.cpp -o gdal-bindings.o gdal-bindings.cpp: In function ‘char* asString(SEXPREC*, int)’: gdal-bindings.cpp:28: error: invalid conversion from ‘const char*’ to ‘char*’ make: *** [gdal-bindings.o] Error 1 ERROR: compilation failed for package ‘rgdal’ * Removing ‘/home/toro/R/i486-pc-linux-gnu-library/2.9/rgdal’ and this happens also for other versions of gdal I have downloaded. The biggest problem is that also other packages like spgrass6, spGDAL and spmaptools are dependent from gdalso i cannot go on Can I ask you to help me , please?? Thank you Matteo __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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. - Roger Bivand Economic Geography Section Department of Economics Norwegian School of Economics and Business Administration Helleveien 30 N-5045 Bergen, Norway -- View this message in context: http://r.789695.n4.nabble.com/rgdal-package-Matteo-Toro-tp2999502p3000144.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.
Re: [R] read.zoo issues
Okay ... now I gotcha ... Thanks -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: 18 October 2010 17:19 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] read.zoo issues On Mon, Oct 18, 2010 at 4:24 AM, Santosh Srinivas santosh.srini...@gmail.com wrote: I am getting problems using read.zoo I have the following data frame head(anlyNiftyDat[,1:10]) TIMESTAMP ACC AMBUJACEM AXISBANK BAJAJ-AUTO BHARTIARTL BHEL BPCL CAIRN CIPLA 1 2010-01-04 00:00:00 913.60 106.10 992.10 1732.05 325.20 2426.10 650.75 285.50 337.55 2 2010-01-05 00:00:00 901.75 105.30 1012.80 1740.05 330.35 2435.40 640.95 295.85 331.50 3 2010-01-06 00:00:00 907.60 105.95 995.80 1713.15 326.85 2426.25 631.30 299.45 344.90 4 2010-01-07 00:00:00 913.35 105.80 1002.85 1683.10 329.40 2409.50 619.05 307.85 342.05 5 2010-01-08 00:00:00 912.15 105.90 1015.95 1655.25 325.05 2424.10 629.55 306.15 341.10 6 2010-01-11 00:00:00 915.15 106.10 1049.40 1669.55 328.95 2396.95 627.90 300.15 342.30 class(anlyNiftyDat) [1] cast_df data.frame anlyNiftyDatZoo - read.zoo(anlyNiftyDat,split=2,check.names=F) head(anlyNiftyDatZoo[,1:10]) X805.45.1 X805.45.2 X805.45.3 X805.45.4 X805.45.5 X805.45.6 X805.45.7 X805.45.8 X805.45.9 X805.45.10 2010-01-04 NA NA NA NA NA NA NA NA NA NA 2010-01-05 NA NA NA NA NA NA NA NA NA NA 2010-01-06 NA NA NA NA NA NA NA NA NA NA 2010-01-07 NA NA NA NA NA NA NA NA NA NA 2010-01-08 NA NA NA NA NA NA NA NA NA NA 2010-01-11 NA NA NA NA NA NA NA NA NA NA Both the column names and values are thrown off. There is no reason to think that read.zoo should be able to understand cast_df objects from the reshape package. Use the reshape2 package instead which produces ordinary data frames rather than cast_df objects. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] Question about Density Plot
Hi I've attached an example about something I want to do in R. This example was done in a Fortran application called ASGL. Here's an example in matplotlib http://matplotlib.sourceforge.net/examples/pylab_examples/hexbin_demo.html Basically, it's like a scatter plot, but have several additional things. One thing are the grids inside the graph, and the other is a density bar used as a reference to evaluate the frequency of the points. The command that I've always used in R for scatter plots is. plot(l1, l2) I need to know if there is something similar in a library of R, or if I could implement it on my own. Greetings Ignacio test.pdf Description: Adobe PDF document __ 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] p-values from coxph?
On Oct 15, 2010, at 9:21 AM, ?hagen Patrik wrote: Dear List, I each iteration of a simulation study, I would like to save the p- value generated by coxph. I fail to see how to adress the p-value. Do I have to calculate it myself from the Wald Test statistic? No. Look at help(coxph.object). This list the components of a coxph object and explains what they are. You will find that fit - coxph(. fit$wald.test contains the Wald test statistic. I prefer the likelihood ratio test myself 2*diff(fit$loglik), with fit$df degrees of freedom. Hunting with str(...) is a good strategy, but even better is the documentation (when it exists). Terry T. __ 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] VectorComparison
Hi all, I am not exactly fluent in R and I got stuck with this. I would like to compare each elements of a vector A with any of the elements in Vector B. For some reasons it does not work. StartDate = as.Date(01/10/2007, %d/%m/%Y) TimeSpan = seq(StartDate, by = 'days', length = length(myAverageCWVs$X1986)) TickLabels = c(2007-10-01, 2007-11-01, 2007-12-01, 2008-01-01) TimeSpan[1:40] == TickLabels Here I would expect TRUE for teh first entry and then TRUE for the entry related to 2007-11-01. This doesn't seem to be the case. [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE Thanks you in advance for any 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.
Re: [R] Randomly shuffle an array 1000 times
Hi, On Mon, Oct 18, 2010 at 7:37 AM, Peter Francis peterfran...@me.com wrote: Dear List, I have a table i have read into R: Name Yes/No John 0 Frank 1 Ann 0 James 1 Alex 1 etc - 800 different times. What i want to do is shuffle yes/no and randomly re-assign them to the name. I guess you mean that you have a data.frame object. Let's say this is called response. You can get 800 permutations of response like so: R responses - lapply(1:800, function(x) { x - response x[,2] - sample(x[,2]) x }) You can also look at replicate and use it in a similar fashion. I have used sample() and permute(), however there is no way to do this 1000 times. Furthermore, i want to copy the data into a excel spreadsheet in the same order as the data was input so i can build up a distribution of the statistic for each name. It seems like you can do that in R, but if you want to use excel, you can include a call to `write.table` before on x before you return it from the lapply/replicate loop, then have excel import a tab/comma delimited file. There are some R packages that I believe write to excel format directly, but I can't recall what they were ... this might be one: http://www.omegahat.org/RExcelXML/ .. I'm pretty sure there is another, but it escapes me. -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ 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] RODBC Error
On Oct 18, 2010, at 5:23 AM, Paolo Agnolucci wrote: Hi Everyone, I am trying to install RODBC but I get the following error message Error in library.dynam(lib, package, package.lib) : shared library 'RODBC' not found In addition: Warning message: package 'RODBC' was built under R version 2.12.0 Error: package/namespace load failed for 'RODBC' I am using R 2.11.0 and I see that the package was built with 2.12.0. However, this has in my experience never been a problem with other packages I have downloaded in the past. A warning gets issued but that is it. Older versions of RODBC are only in the tar.gz and frankly I have no idea how to compile the source code as my IT knowledge is quite limited. Same applies to 2.12.0 for which I couldnt find any .zip file. Any help? Thanks Ron Don't download the package directly. Use: install.packages(RODBC) from the R command line or from the Windows GUI package menu. Either approach, I believe, should by default point to the 2.11.x CRAN tree and allow you to install the proper version of the package. If, for some reason, you must download the package, use: http://cran.r-project.org/bin/windows/contrib/2.11/RODBC_1.3-2.zip There are Windows binary versions of the CRAN packages in that tree for 2.11.x. There have been significant changes made in 2.12.0 relative to Windows (dealing with the merging of 64/32 bit versions). Thus if you are running an older version of R, you will have problems with the latest binary builds of CRAN packages. This is not the first time that substantive changes have been made to R, where old packages may not be upwardly compatible and/or where you may get warnings. Such changes are typically referenced in the relevant FAQs, README files, manuals and other docs as may be appropriate. For example: http://cran.us.r-project.org/bin/windows/base/CHANGES.R-2.12.0.html HTH, Marc Schwartz __ 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] VectorComparison
Hi, You might consider ?match For example: StartDate = as.Date(01/10/2007, %d/%m/%Y) TimeSpan = seq(StartDate, by = 'days', length = 40) TickLabels = as.Date(c(2007-10-01, 2007-11-01, 2007-12-01, 2008-01-01), %Y-%m-%d) TimeSpan[1:40] == TickLabels # not designed for comparing multiple values on each side TickLabels %in% TimeSpan[1:40] # Find which TickLabels are in TimeSpane TimeSpan[1:40] %in% TickLabels # Find which TimeSpane are in TickLabels HTH, Josh On Mon, Oct 18, 2010 at 5:50 AM, Paolo Agnolucci agnolucp...@googlemail.com wrote: Hi all, I am not exactly fluent in R and I got stuck with this. I would like to compare each elements of a vector A with any of the elements in Vector B. For some reasons it does not work. StartDate = as.Date(01/10/2007, %d/%m/%Y) TimeSpan = seq(StartDate, by = 'days', length = length(myAverageCWVs$X1986)) TickLabels = c(2007-10-01, 2007-11-01, 2007-12-01, 2008-01-01) TimeSpan[1:40] == TickLabels Here I would expect TRUE for teh first entry and then TRUE for the entry related to 2007-11-01. This doesn't seem to be the case. [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE Thanks you in advance for any 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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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.
Re: [R] VectorComparison
Use %in% instead of '==' On Mon, Oct 18, 2010 at 10:50 AM, Paolo Agnolucci agnolucp...@googlemail.com wrote: Hi all, I am not exactly fluent in R and I got stuck with this. I would like to compare each elements of a vector A with any of the elements in Vector B. For some reasons it does not work. StartDate = as.Date(01/10/2007, %d/%m/%Y) TimeSpan = seq(StartDate, by = 'days', length = length(myAverageCWVs$X1986)) TickLabels = c(2007-10-01, 2007-11-01, 2007-12-01, 2008-01-01) TimeSpan[1:40] == TickLabels Here I would expect TRUE for teh first entry and then TRUE for the entry related to 2007-11-01. This doesn't seem to be the case. [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE Thanks you in advance for any 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] Question about Density Plot
Dear Ignacio, if you want it hexagonal (as I gather from the hexbin_demo, have a look at the hexbin package. Otherwise, lattice's levelplot is your friend. Or, if you prefer ggplot: geom_tile or geom_hex. UIf you play a bit with findFn from package sos, e.g. findFn (plot 2d density) findFn (plot 2d histogram) you'll find more related functions. Claudia I've attached an example about something I want to do in R. This example was done in a Fortran application called ASGL. Here's an example in matplotlib http://matplotlib.sourceforge.net/examples/pylab_examples/hexbin_demo.html Basically, it's like a scatter plot, but have several additional things. One thing are the grids inside the graph, and the other is a density bar used as a reference to evaluate the frequency of the points. The command that I've always used in R for scatter plots is. plot(l1, l2) I need to know if there is something similar in a library of R, or if I could implement it on my own. Greetings Ignacio __ 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. -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbelei...@units.it __ 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] Sine function fitting
Hi, Is there a package to perform a sine function fitting to XY data? Thx, Ashz -- View this message in context: http://r.789695.n4.nabble.com/Sine-function-fitting-tp3000156p3000156.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] [R-pkgs] new packages: hydroTSM 0.2-0 and hydroGOF 0.2-0
Dear R and hydrological community, The first public (beta) release of two new R packages are now available on CRAN: # hydroTSM # 1) hydroTSM is a package for management and analysis of hydrological time series: http://cran.r-project.org/web/packages/hydroTSM/ hydroTSM includes S3 functions for management, analysis, interpolation and plot of hydrological time series, mainly oriented to hydrological modelling tasks. So far, it only works with daily / monthly / seasonal / annual time series. The focus of this package has been put in providing a collection of functions useful for the daily work of hydrologists, and although an effort was made to optimise each function as much as possible, functionality has had priority over speed. # hydroGOF # 2) hydroGOF is a package for comparison of simulated and observed hydrological time series: http://cran.r-project.org/web/packages/hydroGOF/ hydroGOF includes S3 functions implementing both statistical and graphical goodness-of-fit measures between observed and simulated values, mainly oriented to be used during the calibration, validation, and application of hydrological models. Missing values in observed and/or simulated values can be removed before computations. # Installation # *) From the R console: # Required packages: install.packages(c(zoo, gstat, automap)) # Suggested packages: install.packages(c(sp, maptools, e1071, rgdal)) # hydroTSM install.packages(hydroTSM) # hydroGOF install.packages(hydroGOF) #Links # http://meetingorganizer.copernicus.org/EGU2010/EGU2010-13008.pdf http://www.slideshare.net/posterVienna/egu2010-ra-statisticalenvironmentfordoinghydrologicalanalysis # Beta Notice # hydroTSM and hydroGOF have been tested for more than a year, but its development began in early 2008, during the Ph.D programme of the author at the University of Trento. Both packages are reasonably stable, but they are currently flagged as beta work, in order to get some feedback from a broader audience. Bugs / comments / questions / collaboration of any kind are very welcomed, and in particular, datasets that can be included in the packages for academic purposes. Kind regards, Mauricio Zambrano-Bigiarini === FLOODS Action Land Management and Natural Hazards Unit Institute for Environment and Sustainability European Commission, Joint Research Centre === Linux user #454569 -- Ubuntu user #17469 === Learning is not attained by chance, it must be sought for with ardor and attended to with diligence. (Abigail Adams, 1744 - 1818) === DISCLAIMER:\ The views expressed are purely those of th...{{dropped:7}} __ 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] Error: subscript out of bounds
IRD, It would certainly be more helpful to us if you showed more of your code or what the dataset IWJR.missing is. Here's a couple of suggestions though. I can see what you are doing is picking a random sample of this dataset. Is the IWJR.missing object a data frame or a vector or what? Typically you use length with vectors and nrow with data frames. Also if you have a vector then the appropriate line for this is, IWJR.missing[sample(1:length(IWJR.missing),1)] Since vectors have no columns. Remember that in data frames and matrices you can refer to a data point by its row and column number [ row , column ] , but you don't have columns in vector objects so you would refer to a data point by it's location in the vector [ location ] You can check this with is.vector or is.data.frame if you're not sure. Also, generally this error can occur if R thinks you are referring to a data point that is outside the range of your data. For example in a data frame of 100 rows, R would give this error if you asked for the 101 st row. Check to make sure that you're aren't select something outside your dataset. Still my first guess is that you have mistaken what the object IWJR.missing is. Try looking at that first. Adrienne Wootten NCSU On Mon, Oct 18, 2010 at 12:35 AM, IRD ird_u...@hotmail.com wrote: Dear All I have problem with this: IWJR.temp -IWJR.missing[sample(1:length(IWJR.missing),1),] Error: subscript out of bounds How I can solved this. Thanks IRD __ 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. [[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] [R-pkgs] OpenMX structural equation software
Dear R users, The OpenMx developer team takes great pride in announcing the availability of OpenMx 1.0. The team would like to express its gratitude to the large number of beta-testers who have helped us improve the code. Thank you. OpenMx is a free suite of R functions and a estimation back-end that supports fitting a wide variety of structural equation models including multiple groups, full information ML for missing data, ordinal estimation with thresholds, multilevel, latent class, and mixture distributions to name a few. The most current version of OpenMx (for Mac, Windows and most Linux variants) may be downloaded by issuing the following R command: source('http://openmx.psyc.virginia.edu/getOpenMx.R') OpenMx is not currently hosted on CRAN due to a license restriction on the one portion of our code, an optimizer, that was not written by the project. We hope to remedy this situation reasonably soon as we are working on an open source version of the optimizer. The remainder of the project is licensed under Apache 2.0 and the source code may be downloaded from the OpenMx website and used for any purpose you wish. We do hope that you wish to contribute improvements or bug fixes back to the project, but we do not require it. The OpenMx website is http://openmx.psyc.virginia.edu, where we host a set of manuals and tutorials, a wiki, and a set of user forums where issues to do with OpenMx and SEM in general can be discussed. We require free registration in order to post to the forums or wiki so as to slow down the spambots, but everything else is available without registration. OpenMx has been in development for 3 years. The OpenMx beta test program began in October 2009. Since then, we have improved the interface and sped up the optimization times considerably. Many new features are in the works and we encourage you to post to the Wish List forum so that we know what you would like to see. From this point on, we will maintain two binary releases: a stable release numbered as 1.x.x, and a development binary with the latest and greatest features and bug-fixes, numbered with the current revision number (e.g., 1448). The development of OpenMx is on-going and we expect that new development binaries will be released often. The stable releases are likely to be updated every few months or so. For the OpenMx team. John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] Any demand for a useR 2011 tutorial on Emacs Speaks Statistics?
Dear all, I'm thinking of organising a tutorial on Emacs Speaks Statistics (ESS) for next year's useR meeting. http://www.warwick.ac.uk/statsdept/useR-2011/ Tony (Rossini) organised one a few years ago which covered the following topics: \begin{enumerate} \item Introduction (now, 15 minutes) \item Using Emacs (45 minutes) \item Using ESS (60 minutes) \item Exercise 1: ESS \item Exercise 2: Sweave \item Emacs extensions (30 minutes) \item Emacs Lisp (30 minutes) \item Discussion and Misc Topics (related Emacs tools, ESS extensions, future designs) \end{enumerate} I think that covers pretty much the material I'd first think of covering, with a few queries: - should it be assumed that users have prior experience to Emacs? - as well as Sweave, I'd like to cover Org mode and its framework for literate programming, which I think is quite nice (babel). If you have any suggestions for what you'd like to see in the tutorial, please email before 29 October, thanks! Stephen __ 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] Question
Margaret, I'm not so sure about the pseudo or quasi random value, and without more information about what you are trying to do I can't provide any more than the following. in your R console, ? rnorm rnorm is the function for pulling random variables from a normal distribution, and defaults to have mean 0 and standard deviation 1. There are many other distributions you can pull random values from, include uniform and gamma distributions. ? runif ? rgamma For the other distributions, please explore the html help from the R console to find more. Also if you are looking at pulling a random line from a dataset consider using the sample function ? sample Adrienne Wootten NCSU On Mon, Oct 11, 2010 at 1:32 PM, Margaretta 2014 margaretta_...@rambler.ruwrote: Hello. I would be very grateful if you could help me in using R. I need R commands of pseudo random value and qvazi (quazi) random value. I found commands qnorm and pnorm, but I am not sure that this is the same as I am looking for. Looking forward to hearing from you. Thank you Margaret __ 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. [[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] VectorComparison
Yes - that worked. Thank you. Incidentally I was also comparing a date to a string which surely didn't help Thanks again Ron On Mon, Oct 18, 2010 at 2:01 PM, Henrique Dallazuanna www...@gmail.comwrote: Use %in% instead of '==' On Mon, Oct 18, 2010 at 10:50 AM, Paolo Agnolucci agnolucp...@googlemail.com wrote: Hi all, I am not exactly fluent in R and I got stuck with this. I would like to compare each elements of a vector A with any of the elements in Vector B. For some reasons it does not work. StartDate = as.Date(01/10/2007, %d/%m/%Y) TimeSpan = seq(StartDate, by = 'days', length = length(myAverageCWVs$X1986)) TickLabels = c(2007-10-01, 2007-11-01, 2007-12-01, 2008-01-01) TimeSpan[1:40] == TickLabels Here I would expect TRUE for teh first entry and then TRUE for the entry related to 2007-11-01. This doesn't seem to be the case. [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE Thanks you in advance for any 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] *REMINDER* useR! 2011 call for tutorials
As announced, the R user conference useR! 2011 is scheduled for August 16-18, 2011, and will take place at the University of Warwick, Coventry, UK. Before the official program, half-day tutorials will be offered on Monday, August 15. We invite R users to submit proposals for three hour tutorials on special topics regarding R. The proposals should give a brief description of the tutorial, including goals, detailed outline, justification of why the tutorial is important, background knowledge required and potential attendees. The proposals should be sent before October 29, 2010 to useR-2011_at_R-project.org. A web page offering more information on the `useR!' conference is available at http://www.R-project.org/useR-2011 We hope to see you in Coventry! The organizing committee: John Aston, Julia Brettschneider, David Firth, Ashley Ford, Ioannis Kosmidis, Tom Nichols, Elke Thönnes and Heather Turner __ 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] aggregate with cumsum
Gabor, You are suggesting some very advanced usage that I do not understand, but it seems this is not what I meant when I said loop. I have a df with 47k rows and each of these is fed to a 'predict' which will output about 62 rows, so the number of groups is very large and I implied that I would go through the 47k x 62 rows with For (jj in (set of 47k values)) # tmp.df=big.df[big.df$group==jj,] to subset # and then sum Which is very slow. I discovered that even creating the dataset is super slow as I use write.table The clogging comes from write.table(tmp,predcom.csv,row.names=FALSE,col.names=FALSE,append=TRUE,sep=',') Can anybody suggest a faster way of appending to a text file?? All comments are appreciated. Stephen B -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: Tuesday, October 12, 2010 4:16 PM To: Bond, Stephen Cc: r-help@r-project.org Subject: Re: [R] aggregate with cumsum On Tue, Oct 12, 2010 at 1:40 PM, Bond, Stephen stephen.b...@cibc.com wrote: Hello everybody, Data is myd - data.frame(id1=rep(c(a,b,c),each=3),id2=rep(1:3,3),val=rnorm(9)) I want to get a cumulative sum over each of id1. trying aggregate does not work myd$pcum - aggregate(myd[,c(val)],list(orig=myd$id1),cumsum) Please suggest a solution. In real the dataframe is huge so looping with for and subsetting is not a great idea (still doable, though). Looping can be slow but its not necessarily so. Here are three approaches to using ave with cumsum to solve this problem. The benchmark shows that the loop is actually the fastest: N - 1e4 k - 10 myd - data.frame(id1=rep(letters[1:k],each=N),id2=rep(1:k,N),val=rnorm(k*N)) library(rbenchmark) benchmark(order = relative, replications = 100, loop = { loop - myd for(i in 2:3) loop[, i] - ave(myd[, i], myd[, 1], FUN = cumsum) }, nonloop1 = { nonloop1 - transform(myd, id2 = ave(id2, id1, FUN = cumsum), val = ave(val, id1, FUN = cumsum) )}, nonloop2 = { f - function(i) ave(myd[, i], myd[, 1], FUN = cumsum) nonloop2 - replace(myd, 2:3, lapply(2:3, f)) } ) identical(loop, nonloop1) identical(loop, nonloop2) The output on my laptop is: test replications elapsed relative user.self sys.self user.child sys.child 1 loop 1008.52 1.00 8.07 0.10 NANA 3 nonloop2 1008.94 1.049296 8.29 0.17 NANA 2 nonloop1 100 11.65 1.367371 10.71 0.22 NANA -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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.
Re: [R] function using values separated by a comma
Try this (I think your result in [2,2] is incorrect): dat - read.table(tc - textConnection( + '0,1 1,3 40,10 0,0 + 20,5 4,2 10,40 10,0 + 0,11 1,2 120,10 0,0'), as.is = TRUE) closeAllConnections() # split the data and create new matrix newDat - lapply(dat, function(.col){ + # split by comma, unlist, convert to numeric and divide + x1 - matrix(as.numeric(unlist(strsplit(.col, ','))), nrow = 2) + x1[1, ] / colSums(x1) + }) do.call(cbind, newDat) V1V2 V3 V4 [1,] 0.0 0.250 0.80 NaN [2,] 0.8 0.667 0.20 1 [3,] 0.0 0.333 0.923077 NaN On Mon, Oct 18, 2010 at 2:37 AM, burgundy saub...@yahoo.com wrote: Hi, Thanks again for your help with this. I would like to use a variation of this function in a similar dataset (numeric) with elements separated by a comma e.g. dat - read.table(tc - textConnection( '0,1 1,3 40,10 0,0 20,5 4,2 10,40 10,0 0,11 1,2 120,10 0,0'), sep=) to simply calculate the frequency of the first number divided by the total number, i.e. x[1]/sum(x). to produce: [,1] [,2] [,3] [,4] [1,] 0 0.25 0.8 NaN [2,] 0.8 0.33 0.2 1 [3,] 0 0.33 0.92 NaN My actual dataset is an enormous file (800,000 rows and 100 columns). Any advice on how I can do this, maybe using gsubfn? Thank you very much! -- View this message in context: http://r.789695.n4.nabble.com/function-using-values-separated-by-a-comma-tp2967870p2999723.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. -- 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] aggregate with cumsum
On Mon, Oct 18, 2010 at 9:55 AM, Bond, Stephen stephen.b...@cibc.com wrote: Gabor, You are suggesting some very advanced usage that I do not understand, but it seems this is not what I meant when I said loop. I have a df with 47k rows and each of these is fed to a 'predict' which will output about 62 rows, so the number of groups is very large and I implied that I would go through the 47k x 62 rows with For (jj in (set of 47k values)) # tmp.df=big.df[big.df$group==jj,] to subset # and then sum Which is very slow. I discovered that even creating the dataset is super slow as I use write.table The clogging comes from write.table(tmp,predcom.csv,row.names=FALSE,col.names=FALSE,append=TRUE,sep=',') Can anybody suggest a faster way of appending to a text file?? All comments are appreciated. If the problem is to sum each row of a matrix then rowSums can do that without a loop. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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.
Re: [R] plotting Zipf and Zipf-Mandelbrot curves in R
Hi! Using R, I plotted a log-log plot of the frequencies in the Brown Corpus using plot(sort(file.tfl$f, decreasing=TRUE), xlab=rank, ylab=frequency, log=x,y) However, I would also like to add lines showing the curves for a Zipfian distribution and for Zipf-Mandelbrot. It's fairly straightforward to add such curves to the plot above with lines(), e.g. for Zipf-Mandelbrot k - 1:length(file.tfl$f) f - C / (k + b)^a # Zipf-Mandelbrot law with parameters a = 1, b = 0, C lines(k, f, lwd=2, col=red) The tricky part is to determine suitable values for the parameters a, b and C. If you happen to be using the zipfR package (just guessing because of the .tfl terminology in your code example), you can easily get an approximation to the Zipf-Mandelbrot law from a trained ZM model (the package does not offer a valid LNRE model for Zipf's original law). In essence, this is what you have to do: file.zm - lnre(zm, tfl2spc(file.tfl)) # assuming that file.tfl is a tfl object created by zipfR k - 1:length(file.tfl$f) f - tqlnre(file.zm, k) * N(file.tfl) lines(k, f, lwd=2, col=red) Hope this helps, Stefan __ 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] questions on unstack()
Folks, I have the following dataframe: x - structure(list(name = c(EU B, EU B, EU B, EU B, EU B, EU B, AU A, AU A, AU A, AU A, AU A, AU A), date = c(2010-10-11, 2010-10-12, 2010-10-13, 2010-10-14, 2010-10-15, 2010-10-18, 2010-10-11, 2010-10-12, 2010-10-13, 2010-10-14, 2010-10-15, 2010-10-18), Jem = c(1.3924, 1.3888, 1.3867, 1.3949, 1.4054, 1.3992, 0.9864, 0.9859, 0.9842, 0.9919, 0.9925, 0.9901), Bim = c(1.3888, 1.3867, 1.3949, 1.4054, 1.3977, 1.3917, 0.9859, 0.9842, 0.9919, 0.9925, 0.9907, 0.9881)), .Names = c(name, date, Jem, Bim ), row.names = c(1L, 2L, 3L, 4L, 5L, 8L, 9L, 10L, 11L, 12L, 13L, 16L), na.action = structure(c(6L, 7L, 14L, 15L), .Names = c(6, 7, 14, 15), class = omit), class = data.frame) x name dateJemBim 1 EU B 2010-10-11 1.3924 1.3888 2 EU B 2010-10-12 1.3888 1.3867 3 EU B 2010-10-13 1.3867 1.3949 4 EU B 2010-10-14 1.3949 1.4054 5 EU B 2010-10-15 1.4054 1.3977 8 EU B 2010-10-18 1.3992 1.3917 9 AU A 2010-10-11 0.9864 0.9859 10 AU A 2010-10-12 0.9859 0.9842 11 AU A 2010-10-13 0.9842 0.9919 12 AU A 2010-10-14 0.9919 0.9925 13 AU A 2010-10-15 0.9925 0.9907 16 AU A 2010-10-18 0.9901 0.9881 I'm trying to collapse the frame so that I get columns of names: unstack(x, Jem ~ name) AU.A EU.B 1 0.9864 1.3924 2 0.9859 1.3888 3 0.9842 1.3867 4 0.9919 1.3949 5 0.9925 1.4054 6 0.9901 1.3992 Three questions: 1. The column names are converted from EU B to EU.B - how to preserve the original names? 2. The column names are sorted alphabetically - how to preserve the original order? I tried unstack(x, terms(Jem ~ name, keep.order = TRUE)) but it doesn't really do anything. 3. If I declare a variable wantedName - 'Jem', how can I use it to perform the unstack: unstack(x, `wantedName` ~ name) Error in tapply(eval(form[[2L]], x), eval(form[[3L]], x), as.vector) : arguments must have same length Thanks, Murali __ 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] Download.file problem
Strange problem with download.file . for non existent URL an empty file is created but I am not able to delete the without shutting down R Example: download.file(http://test.com/test.txt,test.txt;) trying URL 'http://test.com/test.txt' Error in download.file(http://test.com/test.txt;, test.txt) : cannot open URL 'http://test.com/test.txt' In addition: Warning message: In download.file(http://test.com/test.txt;, test.txt) : cannot open: HTTP status was '404 Not Found' If you go to working directory through windows explorer, you can see the empty file test.txt but try deleteting the file and it says that the file is locked. I tried closeAllConnections() but of no use. Any suggestions? Thanks, S __ 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] remove numbers from string of characters
Greetings I want to remove numbers from a string of characters that identify sites so that I can merge two data frames. For example, a site in one frame is called 001a Frozen Niagara Entrance whereas the same site in the other data frame is called Frozen Niagara Entrance. It seems to me the easiest thing to do would be to remove the numbers from the first data frame so the two will match. How do I go about removing those numbers? Thanks in advance. Cheers Kurt *** Kurt Lewis Helf, Ph.D. Ecologist EEO Counselor National Park Service Cumberland Piedmont Network P.O. Box 8 Mammoth Cave, KY 42259 Ph: 270-758-2163 Lab: 270-758-2151 Fax: 270-758-2609 Science, in constantly seeking real explanations, reveals the true majesty of our world in all its complexity. -Richard Dawkins The scientific tradition is distinguished from the pre-scientific tradition in having two layers. Like the latter it passes on its theories but it also passes on a critical attitude towards them. The theories are passed on not as dogmas but rather with the challenge to discuss them and improve upon them. -Karl Popper ...consider yourself a guest in the home of other creatures as significant as yourself. -Wayside at Wilderness Threshold in McKittrick Canyon, Guadalupe Mountains National Park, TX Cumberland Piedmont Network (CUPN) Homepage: http://tiny.cc/e7cdx CUPN Forest Pest Monitoring Website: http://bit.ly/9rhUZQ CUPN Cave Cricket Monitoring Website: http://tiny.cc/ntcql CUPN Cave Aquatic Biota Monitoring Website: http://tiny.cc/n2z1o __ 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] Extracting elements from a nested list
Hi, I have a list of n items and the ith element has m_i elements within it. I want to do something like: predicted.values- lapply(all.predicted.values,'[[',max.growth[[i]]) Where max.growth[[i]] is the element I want to extract from each of the ith predicted elements. Thus, for example, I want to extract the max.growth[[1]] element from all.predicted.values[[1]] (which is itself a list). Then I want to extract max.growth[[2]] element from all.predicted.values[[2]]. I realize I can do this with a for loop but then if I can do this as one line that would be preferable. Thanks! Greg [[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] remove numbers from string of characters
See agrep function: agrep(Frozen Niagara Entrance, 001a Frozen Niagara Entrance) 0 To remove the numbers: gsub(\\d, , 001a Frozen Niagara Entrance) On Mon, Oct 18, 2010 at 12:58 PM, kurt_h...@nps.gov wrote: Greetings I want to remove numbers from a string of characters that identify sites so that I can merge two data frames. For example, a site in one frame is called 001a Frozen Niagara Entrance whereas the same site in the other data frame is called Frozen Niagara Entrance. It seems to me the easiest thing to do would be to remove the numbers from the first data frame so the two will match. How do I go about removing those numbers? Thanks in advance. Cheers Kurt *** Kurt Lewis Helf, Ph.D. Ecologist EEO Counselor National Park Service Cumberland Piedmont Network P.O. Box 8 Mammoth Cave, KY 42259 Ph: 270-758-2163 Lab: 270-758-2151 Fax: 270-758-2609 Science, in constantly seeking real explanations, reveals the true majesty of our world in all its complexity. -Richard Dawkins The scientific tradition is distinguished from the pre-scientific tradition in having two layers. Like the latter it passes on its theories but it also passes on a critical attitude towards them. The theories are passed on not as dogmas but rather with the challenge to discuss them and improve upon them. -Karl Popper ...consider yourself a guest in the home of other creatures as significant as yourself. -Wayside at Wilderness Threshold in McKittrick Canyon, Guadalupe Mountains National Park, TX Cumberland Piedmont Network (CUPN) Homepage: http://tiny.cc/e7cdx CUPN Forest Pest Monitoring Website: http://bit.ly/9rhUZQ CUPN Cave Cricket Monitoring Website: http://tiny.cc/ntcql CUPN Cave Aquatic Biota Monitoring Website: http://tiny.cc/n2z1o __ 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] questions on unstack()
Try this: data.frame(split(x$Jem, factor(x$name, levels = unique(x$name))), check.names = FALSE) third question: unstack(x, as.formula(sprintf('%s ~ name', wantedName))) On Mon, Oct 18, 2010 at 12:47 PM, murali.me...@avivainvestors.com wrote: Folks, I have the following dataframe: x - structure(list(name = c(EU B, EU B, EU B, EU B, EU B, EU B, AU A, AU A, AU A, AU A, AU A, AU A), date = c(2010-10-11, 2010-10-12, 2010-10-13, 2010-10-14, 2010-10-15, 2010-10-18, 2010-10-11, 2010-10-12, 2010-10-13, 2010-10-14, 2010-10-15, 2010-10-18), Jem = c(1.3924, 1.3888, 1.3867, 1.3949, 1.4054, 1.3992, 0.9864, 0.9859, 0.9842, 0.9919, 0.9925, 0.9901), Bim = c(1.3888, 1.3867, 1.3949, 1.4054, 1.3977, 1.3917, 0.9859, 0.9842, 0.9919, 0.9925, 0.9907, 0.9881)), .Names = c(name, date, Jem, Bim ), row.names = c(1L, 2L, 3L, 4L, 5L, 8L, 9L, 10L, 11L, 12L, 13L, 16L), na.action = structure(c(6L, 7L, 14L, 15L), .Names = c(6, 7, 14, 15), class = omit), class = data.frame) x name dateJemBim 1 EU B 2010-10-11 1.3924 1.3888 2 EU B 2010-10-12 1.3888 1.3867 3 EU B 2010-10-13 1.3867 1.3949 4 EU B 2010-10-14 1.3949 1.4054 5 EU B 2010-10-15 1.4054 1.3977 8 EU B 2010-10-18 1.3992 1.3917 9 AU A 2010-10-11 0.9864 0.9859 10 AU A 2010-10-12 0.9859 0.9842 11 AU A 2010-10-13 0.9842 0.9919 12 AU A 2010-10-14 0.9919 0.9925 13 AU A 2010-10-15 0.9925 0.9907 16 AU A 2010-10-18 0.9901 0.9881 I'm trying to collapse the frame so that I get columns of names: unstack(x, Jem ~ name) AU.A EU.B 1 0.9864 1.3924 2 0.9859 1.3888 3 0.9842 1.3867 4 0.9919 1.3949 5 0.9925 1.4054 6 0.9901 1.3992 Three questions: 1. The column names are converted from EU B to EU.B - how to preserve the original names? 2. The column names are sorted alphabetically - how to preserve the original order? I tried unstack(x, terms(Jem ~ name, keep.order = TRUE)) but it doesn't really do anything. 3. If I declare a variable wantedName - 'Jem', how can I use it to perform the unstack: unstack(x, `wantedName` ~ name) Error in tapply(eval(form[[2L]], x), eval(form[[3L]], x), as.vector) : arguments must have same length Thanks, Murali __ 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] aggregate with cumsum
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Gabor Grothendieck Sent: Monday, October 18, 2010 7:03 AM To: Bond, Stephen Cc: r-help@r-project.org Subject: Re: [R] aggregate with cumsum On Mon, Oct 18, 2010 at 9:55 AM, Bond, Stephen stephen.b...@cibc.com wrote: Gabor, You are suggesting some very advanced usage that I do not understand, but it seems this is not what I meant when I said loop. I have a df with 47k rows and each of these is fed to a 'predict' which will output about 62 rows, so the number of groups is very large and I implied that I would go through the 47k x 62 rows with For (jj in (set of 47k values)) # tmp.df=big.df[big.df$group==jj,] to subset # and then sum Which is very slow. I discovered that even creating the dataset is super slow as I use write.table The clogging comes from write.table(tmp,predcom.csv,row.names=FALSE,col.names=FALSE, append=TRUE,sep=',') Can anybody suggest a faster way of appending to a text file?? Writing the output to a file instead of inserting it into an R object almost never gives you more speed. Writing to a text file and later reading from it with read.table or the like can lose a lot of precision. Use one of the R functions Gabor and others have suggested. If you really want to append many times to one file things will go much faster if you open the file before all the writing and close it when you are done, instead of opening and closing it implicitly for each write. E.g., on my Windows XP laptop opening the file once gives a c. 320:1 speedup: tfile1 - tempfile() system.time(for(i in 1:1e4)cat(i, file=tfile1, append=TRUE)) user system elapsed 1.844.30 79.86 tfile2 - tempfile() ofile - file(tfile2, open=a) # open in append mode system.time(for(i in 1:1e4)cat(i, file=ofile)) user system elapsed 0.180.070.25 close(ofile) and there is not difference in what the output files contain. identical(readLines(tfile1), readLines(tfile2)) [1] TRUE Warning messages: 1: In readLines(tfile1) : incomplete final line found on 'C:\DOCUME~1\wdunlap\LOCALS~1\Temp\Rtmpdy7MQ0\file41bb5af1' 2: In readLines(tfile2) : incomplete final line found on 'C:\DOCUME~1\wdunlap\LOCALS~1\Temp\Rtmpdy7MQ0\file1eb26e9' write.table() has a lot of additional overhead beyond opening and closing files. Using cat() is the fastest. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com All comments are appreciated. If the problem is to sum each row of a matrix then rowSums can do that without a loop. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] Extracting elements from a nested list
Try this: diag(sapply(all.predicted.values, '[[', 'max.growth')) On Mon, Oct 18, 2010 at 12:59 PM, Gregory Ryslik rsa...@comcast.net wrote: Hi, I have a list of n items and the ith element has m_i elements within it. I want to do something like: predicted.values- lapply(all.predicted.values,'[[',max.growth[[i]]) Where max.growth[[i]] is the element I want to extract from each of the ith predicted elements. Thus, for example, I want to extract the max.growth[[1]] element from all.predicted.values[[1]] (which is itself a list). Then I want to extract max.growth[[2]] element from all.predicted.values[[2]]. I realize I can do this with a for loop but then if I can do this as one line that would be preferable. Thanks! Greg [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] Extracting elements from a nested list
Unfortunately, that gives me null everywhere. Here's the data I have for all.predicted.values and max.growth. Perhaps this will help. Thus I want all.predicted.values[[1]][[4]] then all.predicted.values[[2]][3]] and then all.predicted.values[[3]][[4]]. I've attached what your statement outputs at the end. Thanks again! Browse[2] max.growth [[1]] [1] 4 [[2]] [1] 3 [[3]] [1] 4 Browse[2] all.predicted.values [[1]] [[1]][[1]] [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [55] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Levels: 0 1 2 [[1]][[2]] [1] 2 2 2 0 2 0 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 0 0 2 2 2 2 0 0 0 2 2 0 0 2 2 0 2 2 2 2 2 0 2 2 2 0 2 2 0 [55] 0 0 2 0 2 0 0 0 0 2 2 2 2 0 2 2 2 0 2 2 0 0 2 2 2 2 2 2 2 0 0 0 2 0 2 2 2 2 0 2 2 2 0 2 0 0 Levels: 0 1 2 [[1]][[3]] [1] 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 2 0 2 2 2 0 0 0 2 0 0 2 0 0 0 0 0 0 0 2 0 0 0 0 0 2 2 0 0 0 2 0 0 0 0 [55] 0 0 2 0 2 0 0 0 0 2 2 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 2 0 0 Levels: 0 1 2 [[1]][[4]] [1] 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 2 0 2 2 2 0 0 0 2 0 0 2 0 0 0 0 0 0 0 2 0 0 0 0 0 2 2 0 0 0 2 0 0 0 0 [55] 0 0 2 0 2 0 0 0 0 2 2 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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 0 0 2 2 2 2 2 0 0 2 2 2 0 2 2 0 2 2 2 2 2 0 2 2 2 0 2 2 2 [55] 0 2 2 2 2 2 0 0 2 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Levels: 0 1 2 [[3]][[3]] [1] 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 [55] 0 0 0 0 1 0 0 0 0 1 0 0 1 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 1 0 0 1 1 0 Levels: 0 1 2 [[3]][[4]] [1] 2 2 2 0 1 0 2 2 0 2 1 2 2 0 0 1 1 1 1 0 2 0 0 0 2 0 0 0 1 2 0 0 0 0 1 2 0 0 1 2 0 1 1 2 0 0 0 2 2 0 0 1 2 0 [55] 0 0 0 0 1 0 0 0 0 1 0 2 1 1 1 2 0 0 1 2 1 1 1 2 1 2 2 2 1 1 0 0 1 0 2 1 1 2 1 1 1 2 0 1 1 0 Levels: 0 1 2 Browse[2] predicted.values.for.max.growth-diag(sapply(all.predicted.values,'[[','max.growth')) Browse[2] predicted.values.for.max.growth [[1]] NULL [[2]] [1] 0 [[3]] [1] 0 [[4]] [1] 0 [[5]] NULL [[6]] [1] 0 [[7]] [1] 0 [[8]] [1] 0 [[9]] NULL On Oct 18, 2010, at 11:08 AM, Henrique Dallazuanna wrote: Try this: diag(sapply(all.predicted.values, '[[', 'max.growth')) On Mon, Oct 18, 2010 at 12:59 PM, Gregory Ryslik rsa...@comcast.net wrote: Hi, I have a list of n items and the ith element has m_i elements within it. I want to do something like: predicted.values- lapply(all.predicted.values,'[[',max.growth[[i]]) Where max.growth[[i]] is the element I want to extract from each of the ith predicted elements. Thus, for example, I want to extract the max.growth[[1]] element from all.predicted.values[[1]] (which is itself a list). Then I want to extract max.growth[[2]] element from all.predicted.values[[2]]. I realize I can do this with a for loop but then if I can do this as one line that would be preferable. Thanks! Greg [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] remove numbers from string of characters
On 18-Oct-10 14:58:05, kurt_h...@nps.gov wrote: Greetings I want to remove numbers from a string of characters that identify sites so that I can merge two data frames. For example, a site in one frame is called 001a Frozen Niagara Entrance whereas the same site in the other data frame is called Frozen Niagara Entrance. It seems to me the easiest thing to do would be to remove the numbers from the first data frame so the two will match. How do I go about removing those numbers? Thanks in advance. Cheers Kurt Try something based on: X - 001a Frozen Niagara Entrance sub([[:alnum:]]* ,,X) # [1] Frozen Niagara Entrance Hoping this helps! Ted. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 18-Oct-10 Time: 16:19:08 -- XFMail -- __ 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] Extracting elements from a nested list
Try posting your data using 'dput' so it is easily read for testing. On Mon, Oct 18, 2010 at 11:17 AM, Gregory Ryslik rsa...@comcast.net wrote: Unfortunately, that gives me null everywhere. Here's the data I have for all.predicted.values and max.growth. Perhaps this will help. Thus I want all.predicted.values[[1]][[4]] then all.predicted.values[[2]][3]] and then all.predicted.values[[3]][[4]]. I've attached what your statement outputs at the end. Thanks again! Browse[2] max.growth [[1]] [1] 4 [[2]] [1] 3 [[3]] [1] 4 Browse[2] all.predicted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2 2 2 2 2 Levels: 0 1 2 [[3]][[3]] [1] 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 [55] 0 0 0 0 1 0 0 0 0 1 0 0 1 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 1 0 0 1 1 0 Levels: 0 1 2 [[3]][[4]] [1] 2 2 2 0 1 0 2 2 0 2 1 2 2 0 0 1 1 1 1 0 2 0 0 0 2 0 0 0 1 2 0 0 0 0 1 2 0 0 1 2 0 1 1 2 0 0 0 2 2 0 0 1 2 0 [55] 0 0 0 0 1 0 0 0 0 1 0 2 1 1 1 2 0 0 1 2 1 1 1 2 1 2 2 2 1 1 0 0 1 0 2 1 1 2 1 1 1 2 0 1 1 0 Levels: 0 1 2 Browse[2] predicted.values.for.max.growth-diag(sapply(all.predicted.values,'[[','max.growth')) Browse[2] predicted.values.for.max.growth [[1]] NULL [[2]] [1] 0 [[3]] [1] 0 [[4]] [1] 0 [[5]] NULL [[6]] [1] 0 [[7]] [1] 0 [[8]] [1] 0 [[9]] NULL On Oct 18, 2010, at 11:08 AM, Henrique Dallazuanna wrote: Try this: diag(sapply(all.predicted.values, '[[', 'max.growth')) On Mon, Oct 18, 2010 at 12:59 PM, Gregory Ryslik rsa...@comcast.net wrote: Hi, I have a list of n items and the ith element has m_i elements within it. I want to do something like: predicted.values- lapply(all.predicted.values,'[[',max.growth[[i]]) Where max.growth[[i]] is the element I want to extract from each of the ith predicted elements. Thus, for example, I want to extract the max.growth[[1]] element from all.predicted.values[[1]] (which is itself a list). Then I want to extract max.growth[[2]] element from all.predicted.values[[2]]. I realize I can do this with a for loop but then if I can do this as one line that would be preferable. Thanks! Greg [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the
Re: [R] remove numbers from string of characters
On 18-Oct-10 15:03:22, Henrique Dallazuanna wrote: See agrep function: agrep(Frozen Niagara Entrance, 001a Frozen Niagara Entrance) 0 To remove the numbers: gsub(\\d, , 001a Frozen Niagara Entrance) That results in a Frozen Niagara Entrance, which is not what he said he wants (his numbers are not purely digital)! You need sub() and [:[alnum:]]* as I suggested previously. Also \\w* would work, since this \\w is equivalent to [[:alnum:]]: sub([[:alnum:]]* , , 001a Frozen Niagara Entrance) # [1] Frozen Niagara Entrance sub(\\w* , , 001a Frozen Niagara Entrance) # [1] Frozen Niagara Entrance On Mon, Oct 18, 2010 at 12:58 PM, kurt_h...@nps.gov wrote: Greetings I want to remove numbers from a string of characters that identify sites so that I can merge two data frames. For example, a site in one frame is called 001a Frozen Niagara Entrance whereas the same site in the other data frame is called Frozen Niagara Entrance. It seems to me the easiest thing to do would be to remove the numbers from the first data frame so the two will match. How do I go about removing those numbers? Thanks in advance. Cheers Kurt E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 18-Oct-10 Time: 16:31:20 -- XFMail -- __ 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] delete data row
I see that both which(condition) and subset(data,condition) both treat NA's in condition that same as FALSE's. This leads people to use those functions for their NA-treating properties instead of for their main functionality (which may not be the best way to get things done). I wonder how much code would break if x[condition], for a logical condition, would break if it returned only the elements of x corresponding to TRUE's in the condition (instead of also returning NA's for NA's in condition). How much currently broken code would start working? I suspect omitting the NA's from the output might be better. I'm don't know about the case of NA's in integer subscripts. This would affect things in the logical case because x[NA] would use the logical case and x[c(1,NA)] the integer. As for your VisTRUE, the following is much faster but silently coerces non-logical arguments to logicals. VisTRUE2 - function(x) !is.na(x) x Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: Sunday, October 17, 2010 6:27 PM To: David Winsemius Cc: William Dunlap; R-help@r-project.org Subject: Re: [R] delete data row I used the -which() construct initially to try to show deleting cases. I believe it hung around longer than it should have. That said, I have also had David's experience with NAs. What about a vectorized version of identical(TRUE, x)? This avoids the which() problem Bill pointed out, and the NA issue David mentioned. Does it introduce new problems? x - 1:10 y - log(x-5) VisTRUE - Vectorize(isTRUE) x[VisTRUE(y -Inf)] Josh On Sun, Oct 17, 2010 at 4:38 PM, David Winsemius dwinsem...@comcast.net wrote: On Oct 17, 2010, at 3:56 PM, William Dunlap wrote: I had been thinking of: x - c(1, (2^(0.5))^2 , 3, 5, (2^(0.5))^2 , 3, 1) y - 2 x[-which(zapsmall(x-y) == 0)] [1] 1 3 5 3 1 Using which() to convert logicals into integer subscripts is almost always unnecessary and often wrong. At one time I believed that too. However, in the situation where the test produces NA rather than a numeric value when one is indexing in the first argument. I have had the unpleasant experience of pages if useless and frustrating to understand output because of this feature. I learned to either use which() in the first argument to [ or to use subset to avoid inadvertent returns from logical indexing. x - 1:10 y - log(x-5) Warning message: In log(x - 5) : NaNs produced x[y-Inf] [1] NA NA NA NA 6 7 8 9 10 x[which(y-Inf)] [1] 6 7 8 9 10 If that test were used in a dataframe indexing, the entire line might come back as a result. In this case it fails when no x is close to y, because integer(0) is the same thing as -integer(0): x[-which(zapsmall(x-10) == 0)] numeric(0) The whichless version, using logical subscripts, works (in this case we want all of x): x[zapsmall(x-10)!=0] [1] 1 2 3 5 2 3 1 Maybe the rule should be don't use the -which construction: x - c(1, (2^(0.5))^2 , 3, 5, (2^(0.5))^2 , 3, 1) y - 2 x[which(zapsmall(x-10) != 0)] [1] 1 2 3 5 2 3 1 -- David. When using logicals as subscripts, read the [ as such that. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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] specifying lme function with a priori hypothesis concerning between-group variation in slopes
I want to specify a 2-level mixed model using the lme function in order to test an a priori hypothesis about the between-group values of the slopes but don't know how to do this . Here is the problem. Consider first the case of a single group. The model is: Y_i= a +bX_i + error where I indexes the different values of X and Y in this group . The a priori hypothesis of the slope is: b=K. This is easily tested with a t-test (b-K=0). Now imagine that there are j groups. For each group j the model is: Y_ij= a_j + b_jX_ij + error. Both the intercepts (a) and the slopes (b) are allowed to vary between groups. The a priori (null) hypothesis of interest involved the between-group values of the slopes and is: b_j=Kj where Kj is specified a priori for each group j based on theoretical considerations but whose values differ between groups. This is clearly a mixed-model problem. I know how to specify the model in lme but I don't know how to set up the inferential test that b_j=Kj for all j groups versus the alternative hypothesis that b_j is not equal to Kj for at least one group. Any help in explaining how to do this using the mle function in R is appreciated. Thanks. Bill Shipley Département de biologie Université de Sherbrooke Sherbrooke (Québec) J1K 2R1 (819) 821-8000, 62079 (819) 821-8049 (Fax) NEW! Shipley, B. (2010). From plant traits to vegetation structure: Chance and selection in the assembly of ecological communities. Cambridge University Press. http://www.amazon.com/Plant-Traits-Vegetation-Structure-Communities/dp/05211 33556/ref=sr_1_3?ie=UTF8s=booksqid=1260148938sr=1-3 __ 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] ncdf installation in R
Sashi Challa wrote: I am trying to install ncdf package on a Linux 64-bit machine. [...] Hi Sashi, Just had a similar issue today. I would suggest the --disable-netcdf4 hasn't been picked up. Try installing an earlier version and using that path instead. See: http://levlafayette.com/node/148 Hope this helps! Hello, Please note that the ncdf package is designed for netcdf library version 3, and the newer ncdf4 package is designed for netcdf library version 4. If you want to install ncdf with version 4 of the netcdf library, you can find instructions at the ncdf/ncdf4 package homepage: http://cirrus.ucsd.edu/~pierce/ncdf/ or just follow the package URL link from CRAN. Regards, --Dave --- David W. Pierce Division of Climate, Atmospheric Science, and Physical Oceanography Scripps Institution of Oceanography (858) 534-8276 (voice) / (858) 534-8561 (fax)dpie...@ucsd.edu __ 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] Randomly shuffle an array multiple times
On Mon, Oct 18, 2010 at 4:38 AM, John Haart anothe...@me.com wrote: Dear List, I have a table i have read into R: Name Yes/No John 0 Frank 1 Ann 0 James 1 Alex 1 etc - 800 different times. What i want to do is shuffle yes/no and randomly re-assign them to the name. I have used sample() and permute(), however there is no way to do this 1000 times. Furthermore, i want to copy the data into a excel spreadsheet in the same order as the data was input so i can build up a distribution of the statistic for each name. When i use shuffle the date gets returned like this - [1] 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1 [34] 0 1 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 [67] 0 0 0 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 [100] 1 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 [133] 0 0 0 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 [166] 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 0 1 [199] 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 [232] 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 [265] 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 [298] 0 1 1 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 0 [331] 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 etc Rather than like this, is there a way to change the output? John 0 Frank 1 Ann 0 James 1 Alex 1 Can anyone suggest a script that would achieve this? I'm sure there is a more elegant way, but here's one. Assume your original table is contained in the variable tab1 that has 2 columns, one with name and one with the 1/0. Do this: nPermutations = 1000; mat1000base = matrix(tab1[, 2], nrow(tab1), nPermutations); set.seed(10) # For reproducibility mat1000 = apply(mat1000base, 2, sample); tab1000 = data.frame(name = tab1[, 1], mat1000); tab1000 is the result you want, you can save it as a csv: write.csv(tab1000, file = tablePermuted1000Times.csv) Peter __ 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] Sine function fitting
Date: Mon, 18 Oct 2010 05:46:14 -0700 From: a...@walla.co.il To: r-help@r-project.org Subject: [R] Sine function fitting Hi, Is there a package to perform a sine function fitting to XY data? Since no one replied AFAIK, are you asking about FFT or something else? It isn't really clear if you have 2D data or Y as a function of X. I suppose that given some objective and a set of data, you could minimize some error metric to fit your not-exactly-sinusoidal samples. You could just peak-detect FFT as one approach and then you get a detailed error analysis ( the spectrum). Thx, Ashz -- View this message in context: http://r.789695.n4.nabble.com/Sine-function-fitting-tp3000156p3000156.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] hdiffplot
Hello, I'm trying to track down more information on hdiffplot than what is supplied in ?hdiffplot. More specifically, the example code found at the bottom ?hdiffplot (##Compare *three* of them:) is something I'm very interested in using for my own analysis. However, I don't see how to add a legend or even how to dig into the bnlst object that is created for determining what the displayed colors mean. The following example helps illustrate what I mean: library(hexbin) x1 - rnorm(1) y1 - rnorm(1) x2 - rnorm(1,mean=1) y2 - rnorm(1,mean=1) x3 - rnorm(1,mean=1) y3 - rnorm(1,mean=0) xbnds - range(x1,x2,x3) ybnds - range(y1,y2,y3) bin1 - hexbin(x1,y1,xbnds=xbnds,ybnds=ybnds) bin2 - hexbin(x2,y2,xbnds=xbnds,ybnds=ybnds) bin3 - hexbin(x3,y3,xbnds=xbnds,ybnds=ybnds) erodebin1 - erode.hexbin(smooth.hexbin(bin1)) erodebin2 - erode.hexbin(smooth.hexbin(bin2)) erodebin3 - erode.hexbin(smooth.hexbin(bin3)) bnlst - list(b1=erodebin1, b2=erodebin2, b3=erodebin3) hdiffplot(bnlst) Can 'grid.hexlegend' be used to add a legend somehow? -Eric -- View this message in context: http://r.789695.n4.nabble.com/hdiffplot-tp3000644p3000644.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.
Re: [R] Crossed random effects in lme
See this email: http://www.mail-archive.com/r-h...@stat.math.ethz.ch/msg10849.html http://www.mail-archive.com/r-h...@stat.math.ethz.ch/msg10849.htmlKevin On Mon, Oct 18, 2010 at 7:06 AM, anord andreas.n...@zooekol.lu.se wrote: Dear all, I am trying to fit a model with crossed random effects using lme. In this experiment, I have been measuring oxygen consumption (mlmin) in bird nestlings, originating from three different treatments (treat), in a respirometer with 7 different channels (ch). I have also measured body mass (mass) for these birds. id nesttreat yearmlmin massch hack 1EP5171117 H 20081.401719138 10.74 2008:17 1EP5170917 H 20081.257163112 9.7 5 2008:17 1EP5171617 H 20081.050170714 10.26 2008:17 1EP5171217 H 20081.330495314 9.6 7 2008:17 1EP51791687 M 20081.07625708 9.7 3 2008:687 1EP51772823 H 20081.336820232 10.24 2008:823 1EP51778613 L 20081.300814516 10.75 2008:613 1EP52336207 M 20081.071775936 10.73 2008:207 1EP52403808 H 20081.142389688 10.35 2008:808 1ER17603838 M 20090.984225217 9.6 3 2009:838 1ER17607838 M 20091.045058894 9.3 4 2009:838 1ER17600247 L 20091.047603048 9.2 5 2009:247 1ER17299247 L 20090.974569658 9.2 6 2009:247 1ER17292617 H 20091.271260094 10.57 2009:617 1ER172067009M 20091.074791644 10.72 2009:7009 1ER17221730 H 20091.423266177 10.24 2009:730 1ER17275863 L 20091.433076022 10.74 2009:863 1ER17277863 L 20091.165236024 9.7 5 2009:863 1ER17283863 L 20091.139311895 10.46 2009:863 1ER17280863 L 20091.056161196 10.47 2009:863 CK59991 690 H 20100.994878996 9.5 2 2010:690 CK59806 161 M 20101.070052025 9.7 6 2010:161 CK59859 545 M 20101.456680579 9.9 4 2010:545 CK59862 545 M 20101.350698793 9.9 5 2010:545 CK59871 223 L 20100.830582186 8.3 6 2010:223 CK59868 223 L 20100.776241825 8 7 2010:223 CL77343 365 M 20101.352454484 10.34 2010:365 CL77338 365 M 20101.327691628 9.6 5 2010:365 CL77356 191 H 20101.212796979 11.31 2010:191 CL77361 191 H 20100.882307732 11.42 2010:191 CL77355 191 H 20101.137097586 10.93 2010:191 I want to include both nesting attempt (hack) and respirometer channel (ch) as random factors in a model trying to explain variation in oxygen consumption. From Pinheiro Bates (2000), I've gathered that this model could be fit making use of pdBlocked and pdIdent, so I've tried fitting the below model: m1.bmr-with(bmred.df,lme(mlmin~treat*year+massout,random=pdBlocked(list(pdIdent(~hack-1),pdIdent(~ch-1))) )) However, my model fails with the following error message: Error in getGroups.data.frame(dataMix, groups) : Invalid formula for groups I would much appreciate any input on this! Kind regards, Andreas Nord Sweden -- View this message in context: http://r.789695.n4.nabble.com/Crossed-random-effects-in-lme-tp3000101p3000101.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. -- Kevin Wright [[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] Extracting elements from a nested list
You probably need mapply since you have 2 list of arguments which you want to use in sync mapply(function(x1,x2)x1[[x2]],all.predicted.values,max.growth) might be what you want. On Oct 18, 2010, at 5:17 PM, Gregory Ryslik wrote: Unfortunately, that gives me null everywhere. Here's the data I have for all.predicted.values and max.growth. Perhaps this will help. Thus I want all.predicted.values[[1]][[4]] then all.predicted.values[[2]][3]] and then all.predicted.values[[3]][[4]]. I've attached what your statement outputs at the end. Thanks again! Browse[2] max.growth [[1]] [1] 4 [[2]] [1] 3 [[3]] [1] 4 Browse[2] all.predicted.values [[1]] [[1]][[1]] [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [55] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Levels: 0 1 2 [[1]][[2]] [1] 2 2 2 0 2 0 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 0 0 2 2 2 2 0 0 0 2 2 0 0 2 2 0 2 2 2 2 2 0 2 2 2 0 2 2 0 [55] 0 0 2 0 2 0 0 0 0 2 2 2 2 0 2 2 2 0 2 2 0 0 2 2 2 2 2 2 2 0 0 0 2 0 2 2 2 2 0 2 2 2 0 2 0 0 Levels: 0 1 2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1 0 Levels: 0 1 2 Browse[2] predicted.values.for.max.growth-diag(sapply(all.predicted.values,'[[','max.growth')) Browse[2] predicted.values.for.max.growth [[1]] NULL [[2]] [1] 0 [[3]] [1] 0 [[4]] [1] 0 [[5]] NULL [[6]] [1] 0 [[7]] [1] 0 [[8]] [1] 0 [[9]] NULL On Oct 18, 2010, at 11:08 AM, Henrique Dallazuanna wrote: Try this: diag(sapply(all.predicted.values, '[[', 'max.growth')) On Mon, Oct 18, 2010 at 12:59 PM, Gregory Ryslik rsa...@comcast.net wrote: Hi, I have a list of n items and the ith element has m_i elements within it. I want to do something like: predicted.values- lapply(all.predicted.values,'[[',max.growth[[i]]) Where max.growth[[i]] is the element I want to extract from each of the ith predicted elements. Thus, for example, I want to extract the max.growth[[1]] element from all.predicted.values[[1]] (which is itself a list). Then I want to extract max.growth[[2]] element from all.predicted.values[[2]]. I realize I can do this with a for loop but then if I can do this as one line that would be preferable. Thanks! Greg [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]]
Re: [R] Basic structure operations doubt
Hi, Well I am not completely sure of the R gurus reasons for what they do, but one explanation is that data is not thrown away unless you ask it to be. Factors are categorical variables and each level could have meaning even when there are no cases in it (or particularly when there are no cases in it). You might have adults split into three age categories, [18, 25), [25, 40), [40, 80], and then look at how many survive a severe car crash (live vs. die) for those wearing a seat belt and those without a seat belt: No Seat Belt [18, 25), [25, 40), [40, 80] Live 0 00 Die 10 0 0 Seat Belt [18, 25), [25, 40), [40, 80] Live 0 95 Die 0 15 or should it be (Live and other ages dropped because no one is in them): No Seat Belt [18, 25) Die 10 As for your other question about assign colNames, I am not completely sure how you want to assign one variable to your other data frame. Do you want to add it? Do you want to replace the one data frames column names? Do you want to assign over a particular row? See ?rbind to bind two or more data frames or matrices together by rows or ?colnames to see how to set a data frames column names. Just as a side note, I really appreciated that you used head() on your data frame so there was actually some sample data to look at. If you want to make the people on R-help super happy, try using: dput(head(yourdata)) and copy that into your email. This gives us an incredibly easy way to actually get the first few rows of your data into R, just like it would be on your end. Best Regards, Josh On Sun, Oct 17, 2010 at 8:30 PM, Santosh Srinivas santosh.srini...@gmail.com wrote: Thanks Josh. At your convenience, Any pointers on why this was designed like this? i.e. shouldn’t droplevels() be the default behavior? I'm missing something in understanding on how these operations (manipulations) were designed to work. -Original Message- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: 18 October 2010 07:47 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Basic structure operations doubt Hi, The easiest way to get rid of the empty levels is with droplevels(). See ?droplevels for details. It actually has a method for data frames even. So you could just do something like: Indx_Constituents - droplevels(Indx_Constituents) or whatever your data frame was called and it will drop any unused levels for you. Cheers, Josh On Sun, Oct 17, 2010 at 7:06 PM, Santosh Srinivas santosh.srini...@gmail.com wrote: I'm doing these manipulations on the data frame and wondering why does R have to remember historical data on my operation and not just keep the needed info. Probably a basic fundamentals of the way R handles data .. Pls point me to the manual if possible .. I have this Index data: head(NIFTY_INDX) �Constituents.list.of.S.P.CNX.Nifty � � � � � � � � � � � � �X � � � X.1 X.2 � � � � �X.3 1 2 � � � � � � � � � � � Company Name � � � � � � � � � Industry � �Symbol Series � �ISIN Code 3 4 � � � � � � � � � � � � � ACC Ltd. CEMENT AND CEMENT PRODUCTS � � � ACC EQ INE012A01025 5 � � � � � � � �Ambuja Cements Ltd. CEMENT AND CEMENT PRODUCTS AMBUJACEM EQ INE079A01024 6 � � � � � � � � � � Axis Bank Ltd. � � � � � � � � � � �BANKS �AXISBANK EQ INE238A01026 I Import the section that is relevant to me: Indx_Constituents - NIFTY_INDX[4:NROW(NIFTY_INDX),] head(Indx_Constituents) �Constituents.list.of.S.P.CNX.Nifty � � � � � � � � � � � � � � �X X.1 X.2 � � � � �X.3 4 � � � � � � � � � � � � � ACC Ltd. � � CEMENT AND CEMENT PRODUCTS ACC �EQ INE012A01025 5 � � � � � � � �Ambuja Cements Ltd. � � CEMENT AND CEMENT PRODUCTS AMBUJACEM �EQ INE079A01024 6 � � � � � � � � � � Axis Bank Ltd. � � � � � � � � � � � � �BANKS AXISBANK �EQ INE238A01026 7 � � � � � � � � � �Bajaj Auto Ltd. AUTOMOBILES - 2 AND 3 WHEELERS BAJAJ-AUTO �EQ INE917I01010 8 � � �Bharat Heavy Electricals Ltd. � � � � � ELECTRICAL EQUIPMENT BHEL �EQ INE257A01018 9 �Bharat Petroleum Corporation Ltd. � � � � � � � � � � REFINERIES BPCL �EQ INE029A01011 colNames - NIFTY_INDX[2,] colNames �Constituents.list.of.S.P.CNX.Nifty � � � �X � �X.1 � �X.2 � � � X.3 2 � � � � � � � � � � � Company Name Industry Symbol Series ISIN Code I want to assign the info from colNames[1,] to Indx_Constituents I am unable to do this directly ... I can probably pull out the values and do it but there should be an easier way Now when I do this: colNames[1,1] [1] Company Name 52 Levels: �ACC Ltd. Ambuja Cements Ltd. Axis Bank Ltd. Bajaj Auto Ltd. Bharat Heavy Electricals Ltd. Bharat Petroleum Corporation Ltd. Bharti Airtel Ltd. Cairn India Ltd. Cipla Ltd. Company Name ... Wipro Ltd. Why does R have to remember the 52 levels?? Why can't it just have the relevant data stored What
[R] Question about legend parameters
Hello! The code below works - if you run it you'll see a stacked area chart generated based on the data example. I only have one understanding question about the legend location (the very last snippet of code): legend(par()$usr[2], mean(par()$usr[3:4]), rev(order.of.vars), xpd=T, bty=n, pch=15, col=all.colors[rev(order.of.colors)]) I see that par()$usr[2] = 14763.72 and mean(par()$usr[3:4]) = 6.215. I've read in ?par that usr is A vector of the form c(x1, x2, y1, y2) giving the extremes of the user coordinates of the plotting region. However, I am not sure I understand par()$usr[subscript] well. Sorry for a very stupid question: Could someone please confirm that my interpretation is correct: Place the left edge of the legend (on x) where the area of the plot ends on the right (on y). Place the left edge of the legend (on y) between the bottom and the top of the current y coordinates of the plot area. Thanks a lot for confirming! Dimitri ### Creating a data set with both positives and negatives my.data-data.frame(date=c(20080301,20080401,20080501,20080601,20080701,20080801,20080901,20081001,20081101,20081201,20090101,20090201,20090301,20090401,20090501,20090601,20090701,20090801,20090901,20091001,20091101,20091201,20100101,20100201,20100301,20100402,20100503), x=c(1.1, 1, 1.6, 1, 2, 1.5, 2.1, 1.3, 1.9, 1.1, 1, 1.6, 1, 2, 1.5, 2.1, 1.3, 1.9, 1.1, 1, 1.6, 1, 2, 1.5, 2.1, 1.3, 1.9), y=c(-4,-3,-6,-5,-7,-5.2,-6,-4,-4.9,-4,-3,-6,-5,-7,-5.2,-6,-4,-4.9,-4,-3,-6,-5,-7,-5.2,-6,-4,-4.9), z=c(-0.2,-0.3,-0.4,-0.1,-0.2,-0.05,-0.2,-0.15,-0.06,-0.2,-0.3,-0.4,-0.1,-0.2,-0.05,-0.2,-0.15,-0.06,-0.06,-0.2,-0.3,-0.4,-0.1,-0.2,-0.05,-0.2,-0.15), a=c(10,13,15,15,16,17,15,16,14,10,13,15,15,16,17,15,16,14,10,13,15,15,16,17,15,16,14)) my.data$date-as.character(my.data$date) my.data$date-as.Date(my.data$date,%Y%m%d) (my.data) str(my.data) ### !!! Enter predictor column numbers here !!! predictor.indexes-2:5 positives-which(colSums(my.data[predictor.indexes])0) # which vars have positive column sums? negatives-which(colSums(my.data[predictor.indexes])0) # which vars have negative column sums? y.max-1.1*max(rowSums(my.data[names(positives)])) # the max on the y axis of the chart y.min-1.1*min(rowSums(my.data[names(negatives)])) # the min on the y axis of the chart ylim - c(y.min, y.max) order.positives-rev(rank(positives)) # start with the largest, then second-largest, etc. order.of.pos.vars-names(order.positives) order.negatives-rev(rank(negatives)) # start with the largest negative, then second-largest, etc. order.of.neg.vars-names(order.negatives) order-c(order.negatives,order.positives) order.of.vars-names(order) # the order of variables on the chart - from the bottom up ### so, the bottom-most area should be for z, the second from the bottom area- for y (above z) ### Creating a palette of 20 colors: all.colors-c(#E0,#D4D4D4,#FFC1C1,#FFDEAD,#9ACD32, #99CCFF,#6495ED,#66CDAA,#EEC900,#BC8F8F, #FF7F00,#C0,#9370DB,#473C8B,#696969, #8B4500,#80,#CD,#104E8B,#228B22) ### Check them out: temp-barplot(1:20,rep(1,20),col=all.colors,horiz=T) xx - c(my.data$date, rev(my.data$date)) bottom.y.coordinates-rowSums(my.data[names(negatives)]) par(mar=c(5,4,4,6),xpd=F) plot(x=my.data$date, y=bottom.y.coordinates, ylim=ylim, col='white', type='l', xaxt='n', ylab='Title for Y', xlab=, main='Chart Title') for(var in order.of.neg.vars){ top.line.coords-bottom.y.coordinates-my.data[[var]] bottom.coords-c(bottom.y.coordinates,rev(top.line.coords)) polygon(xx,bottom.coords,col=all.colors[which(names(my.data[predictor.indexes]) %in% var)]) bottom.y.coordinates-top.line.coords } for(var in order.of.pos.vars){ top.line.coords-bottom.y.coordinates+my.data[[var]] bottom.coords-c(bottom.y.coordinates,rev(top.line.coords)) polygon(xx,bottom.coords,col=all.colors[which(names(my.data[predictor.indexes]) %in% var)]) bottom.y.coordinates-top.line.coords } axis(1, labels =format(as.Date(my.data$date, origin=1970-01-01), %Y-%m-%d), at=my.data$date, las=2,cex.axis=0.7) abline(v=my.data$date,lty=dotted,col = lightgray) abline(h=axTicks(2), lty=dotted,col = lightgray) order.of.colors-NULL for(var in 1:length(order.of.vars)){ # var-2 order.of.colors[[var]]-which(names(my.data[predictor.indexes]) %in% order.of.vars[var]) } str(order.of.colors) legend(par()$usr[2], mean(par()$usr[3:4]), rev(order.of.vars), xpd=T, bty=n, pch=15, col=all.colors[rev(order.of.colors)]) __ 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] Sine function fitting
If you know the period of the sine that you want to fit (just fitting the amplitude, phase shift, and offset) and are willing to assume normal errors (or at least normal enough for the CLT) then you can just use the lm function. If you need to find the period as well (but still willing to assume normal enough errors) then you can use the nls function. You can approximate with splines and lm for another approach. No packages (other than the automatic ones) needed. If you are not willing to assume normal enough errors, then we will need more data to be able to help. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of ashz Sent: Monday, October 18, 2010 6:46 AM To: r-help@r-project.org Subject: [R] Sine function fitting Hi, Is there a package to perform a sine function fitting to XY data? Thx, Ashz -- View this message in context: http://r.789695.n4.nabble.com/Sine- function-fitting-tp3000156p3000156.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.
[R] boxplot ranked x labels
Dear R users, x-values (EI) = Adw, EG1, LA1, Ad1, LA2, LA3...(14 levels, insect stages) y-valus = antpop within the boxplot function x-values are ordered alphabetically Idea: x-values ranked by list order (insect stage: Egg stage 1 is followed by Larvae 1 and not by Egg stage 2 as it would be in an alphabetically order) Problems with the order(tapply()) function: variable lengths differ thanks Sibylle R-code (as later insect stages have higher means, ordering was based on mean or median...) SOPRA-read.table(SOPRA206_WG_WAE.txt, na.strings=0, header=TRUE) ordered-order(tapply(SOPRA$antpop, SOPRA$EI, mean)) boxplot(antpop~ordered, data=SOPRA, boxwex=0.20, at=1:14-0.2, scales=list(x=list(rot=45)), notch=TRUE, xlab = EVENT, ylab = DOY, ylim = c(100,350), yaxs =i, col=red, subset=(wg == ctrl)) boxplot(antpop~ereignis, data=SOPRA, add=TRUE, boxwex=0.20, at=1:14+0.2, xaxt=n, notch=TRUE, col=blue, subset=(wg == scen)) legend(1,330, c(SOPRA206 WGctrl, SOPRA206 WGscen), fill=c(red, blue), bty=n) text(1,340, Waedenswil, font=2, pos=4) [[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] read.spss warning message (Unrecognized record type 7, subtype 18 encountered in system file)
Hello Everyone, Trying to help someone recover the contents of an SPSS.sav file using read.spss. This seemed to work well but produced a warning message. My code and the warning are displayed below. Spent some time looking for previous questions about this warning. Found a lot of questions posted but wasn't able to figure out what the problem is. Is there anyone out there who can explain what's going wrong and how I can fix it? Thanks, Paul dataSPSS-read.spss(N:/Mark.sav,to.data.frame = TRUE) Warning message: In read.spss(N:/Mark.sav, to.data.frame = TRUE) : N:/Mark.sav: Unrecognized record type 7, subtype 18 encountered in system file View(dataSPSS) write.csv(dataSPSS,N:/Mark.csv) [[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] boxplot ranked x labels
Sibylle - Since you didn't give a reproducible example, I'll try to make one that will illustrate what you need to know to answer your question. Suppose we have a variable with levels four,five, and six. ff = factor(rep(c('four','five','six'),c(5,7,2))) Since the table() function will report the levels in the same order as boxplot, I'll use that to illustrate my point: table(ff) ff five four six 752 Suppose we want the levels to appear in the order four, five,six: table(factor(ff,levels=c('four','five','six'))) four five six 572 Now suppose we want to list them in the order of their frequencies: table(factor(ff,levels=rev(names(table(ff) six four five 257 In other words, you can have a factor's levels appear in whatever order you'd like by using the levels= argument to factor. Hope this helps. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Mon, 18 Oct 2010, Sibylle Stöckli wrote: Dear R users, x-values (EI) = Adw, EG1, LA1, Ad1, LA2, LA3...(14 levels, insect stages) y-valus = antpop within the boxplot function x-values are ordered alphabetically Idea: x-values ranked by list order (insect stage: Egg stage 1 is followed by Larvae 1 and not by Egg stage 2 as it would be in an alphabetically order) Problems with the order(tapply()) function: variable lengths differ thanks Sibylle R-code (as later insect stages have higher means, ordering was based on mean or median...) SOPRA-read.table(SOPRA206_WG_WAE.txt, na.strings=0, header=TRUE) ordered-order(tapply(SOPRA$antpop, SOPRA$EI, mean)) boxplot(antpop~ordered, data=SOPRA, boxwex=0.20, at=1:14-0.2, scales=list(x=list(rot=45)), notch=TRUE, xlab = EVENT, ylab = DOY, ylim = c(100,350), yaxs =i, col=red, subset=(wg == ctrl)) boxplot(antpop~ereignis, data=SOPRA, add=TRUE, boxwex=0.20, at=1:14+0.2, xaxt=n, notch=TRUE, col=blue, subset=(wg == scen)) legend(1,330, c(SOPRA206 WGctrl, SOPRA206 WGscen), fill=c(red, blue), bty=n) text(1,340, Waedenswil, font=2, pos=4) [[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] Extracting elements from a nested list
Hi Everyone, This is closer to what I need but this returns me a matrix where each element is a factor. Instead I would want a list of lists. The first entry of the list should equal the first column of the matrix that mapply makes, the second entry to the second column etc... I've attached the two files that have all.predicted.values and max.growth from dput to make for easy testing. Thanks again! Kind regards, Greg On Oct 18, 2010, at 1:33 PM, Erich Neuwirth wrote: You probably need mapply since you have 2 list of arguments which you want to use in sync mapply(function(x1,x2)x1[[x2]],all.predicted.values,max.growth) might be what you want. On Oct 18, 2010, at 5:17 PM, Gregory Ryslik wrote: Unfortunately, that gives me null everywhere. Here's the data I have for all.predicted.values and max.growth. Perhaps this will help. Thus I want all.predicted.values[[1]][[4]] then all.predicted.values[[2]][3]] and then all.predicted.values[[3]][[4]]. I've attached what your statement outputs at the end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 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Levels: 0 1 2 [[3]][[3]] [1] 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 [55] 0 0 0 0 1 0 0 0 0 1 0 0 1 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 1 0 0 1 1 0 Levels: 0 1 2 [[3]][[4]] [1] 2 2 2 0 1 0 2 2 0 2 1 2 2 0 0 1 1 1 1 0 2 0 0 0 2 0 0 0 1 2 0 0 0 0 1 2 0 0 1 2 0 1 1 2 0 0 0 2 2 0 0 1 2 0 [55] 0 0 0 0 1 0 0 0 0 1 0 2 1 1 1 2 0 0 1 2 1 1 1 2 1 2 2 2 1 1 0 0 1 0 2 1 1 2 1 1 1 2 0 1 1 0 Levels: 0 1 2 Browse[2] predicted.values.for.max.growth-diag(sapply(all.predicted.values,'[[','max.growth')) Browse[2] predicted.values.for.max.growth [[1]] NULL [[2]] [1] 0 [[3]] [1] 0 [[4]] [1] 0 [[5]] NULL [[6]] [1] 0 [[7]] [1] 0 [[8]] [1] 0 [[9]] NULL On Oct 18, 2010, at 11:08 AM, Henrique Dallazuanna wrote: Try this: diag(sapply(all.predicted.values, '[[', 'max.growth')) On Mon, Oct 18, 2010 at 12:59 PM, Gregory Ryslik rsa...@comcast.net wrote: Hi, I have a list of n items and the ith element has m_i elements within it. I want to do something like: predicted.values- lapply(all.predicted.values,'[[',max.growth[[i]]) Where max.growth[[i]] is the element I want to extract from each of the ith predicted elements. Thus, for example, I want to extract the max.growth[[1]] element from all.predicted.values[[1]] (which is itself a list). Then I want to extract max.growth[[2]] element from all.predicted.values[[2]]. I realize I can do this with a for loop but then if I can do this as one line that would be preferable. Thanks!
Re: [R] Class mode text isopen can read can write - too many open connections
Hi, I was able to reproduce your problem (I changed the date sequence to starting 01-Oct-2010, but that does not really matter). The interesting thing is that I could delete some files, and they were not random. Whenever Windows showed one of the zip folders' size as 0KB, then I could not delete, but I could delete all the other ones. It makes me think there might have been an error in writing those particular ones which lead both to them not having anything in them and the connection not shutting down properly. If the connections were not shutting down, this would also explain your problem with R having too many open connections. I do not really have a solution though (other than shutting down R), the details of connections and file writing are really beyond my experience. Best regards, Josh On Sun, Oct 17, 2010 at 7:15 PM, Santosh Srinivas santosh.srini...@gmail.com wrote: I'm basically doing using code: NOTE THIS IS A RECURSIVE DOWNLOAD ... SO CHANGE TO A DIRECTORY THAT YOU WANT TO JUNK ... After the download ... try deleting the data without closing R and it says the file is currently held open by R ... Not sure how I can close that connection .. Please let me know any release operations that I ened to add in the code too. library(zoo) library(RCurl) x - seq(as.Date(01-Jan-2010,format=%d-%b-%Y), Sys.Date(), by=1) #to generate series of dates #sDate - x[6] cmDownFun - function (sDate) { sMonth - casefold( as.character(sDate,format=%b),upper=T) #Get the month sYear - casefold( as.character(sDate,format=%Y),upper=T) #Get the month sDate1 - casefold( as.character(sDate, format=%d%b%Y), upper =T) #Get the date sURL - paste(http://www.nseindia.com/content/historical/EQUITIES/,sYear,/,sMonth,/cm,sDate1,bhav.csv.zip;, sep=) tryCatch( { download.file(sURL,paste(CM,sDate1,.zip,sep=)) #download the file print (paste(Successfully downloaded:, paste(CM,sDate1,.zip,sep=))) write(paste(Successfully downloaded:, paste(CM,sDate1,.zip,sep=)),file = Success-Log.txt,append=TRUE,sep=\n) closeAllConnections() }, warning = function (ex){ print(paste(Failed to download:, paste(CM,sDate1,.zip,sep=)),file = Failure-Log.txt,append=TRUE,sep=\n) write(paste(Failed to download:, paste(CM,sDate1,.zip,sep=)),file = Failure-Log.txt,append=TRUE,sep=\n) closeAllConnections() }) } #lapply(x, function(x) try(cmDownFun(x),silent = TRUE)) lapply(x, cmDownFun) -Original Message- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: 17 October 2010 21:39 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Class mode text isopen can read can write - too many open connections Hi, Is it a public URL (i.e., that we can try downloading from too)? Do you get the same error now matter where/what you download or just from that one place? Finally, if you are using Windows XP, are you running R as an administrator (or very sure that the log file or whatever else you are creating is not being written to some place that Windows will try to restrict such as in Programs)? Cheers, Josh On Sun, Oct 17, 2010 at 8:57 AM, Santosh Srinivas santosh.srini...@gmail.com wrote: I am downloading data files using RCurl and everything works except till some limit is hit and says too many connections open It is a simple download using URL and I am writing the status in a tryCatch block to a log file. showConnections() � � description class mode text isopen can read can write showConnections(all=T) �description class � � �mode text � isopen � can read can write 0 stdin � � terminal r �text opened yes � �no 1 stdout � �terminal w �text opened no � � yes 2 stderr � �terminal w �text opened no � � yes I tried closeAllConnections() but of no use. When I try to delete a downloaded file . It says cannot be done because folder is open in R GUI front end Any idea how to resolve this? sessionInfo() R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 �LC_CTYPE=English_United Kingdom.1252 � �LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats � � graphics �grDevices utils � � datasets �methods � base other attached packages: [1] RCurl_1.4-4.1 �bitops_1.0-4.1 zoo_1.6-4 loaded via a namespace (and not attached): [1] grid_2.11.1 � � lattice_0.19-11 tools_2.11.1 __ 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,
[R] Question about lme (mixed effects regression)
Hello! If I run this example: library(nlme) fm1 - lme(distance ~ age+Sex, Orthodont, random = ~ age + Sex| Subject) If I run: summary(fm1) then I can see the fixed effects for age and sex (17.7 for intercept, 0.66 for age, and -1.66 for SexFemale) If I run: ranef(fm1) Then it looks like it's producing the random effects for each subgroup (in this example - each subject). For example, for MO1 it's: 1.25 for intercept, 0.106 for age, and -1.52 for SexFemale. So, in order to get the the total effects, i.e., the regression equation, for each subgroup (Subject) I need to do this: For example, for Subject MO1: y(M01) = (17.71+1.25)+(0.66+0.106)*Age+(-1.66-1.52)*SexFemale = 18.96 + 0.766*Age -3.18*SexFemale Question: Is there an easier way to get such an equation for each level of Subject? Thank you very much! -- Dimitri Liakhovitski Ninah Consulting www.ninah.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.
Re: [R] Extracting elements from a nested list
Hi, It seems that the files did not make it through the mailer. Perhaps it didn't like my extensions. I have now attached the files as .txt's as well as copied in the contents of each file: list(list(structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0, 1, 2), class = factor), structure(c(3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 3L, 3L, 1L, 3L, 1L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3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L, 3L, 2L, 3L, 3L, 2L, 3L, 3L, 2L, 3L, 3L, 2L, 3L, 3L, 2L), .Label = c(0, 1, 2), class = factor), structure(c(3L, 2L, 3L, 2L, 3L, 3L, 1L, 3L, 2L, 2L, 1L, 3L, 3L, 2L, 1L, 3L, 3L, 2L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 2L, 1L, 3L, 1L, 2L, 3L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 3L, 1L, 2L, 1L, 3L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 1L, 3L, 1L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 2L, 3L, 3L, 2L, 3L, 1L, 2L, 1L, 1L, 2L, 3L, 3L, 2L), .Label = c(0, 1, 2), class = factor), structure(c(3L, 1L, 3L, 1L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 3L, 3L, 2L, 1L, 3L, 3L, 1L, 3L, 1L, 2L,
Re: [R] Incorrect positioning of raster images on Windows
Michael Sumner-2 wrote: I think there's something about the discrete cell versus centre value interpretation here, and you are pushing the pixels through R's graphics engine as well as whatever the png device has to do. I can't enlighten you about the details of that, but by creating an image file more directly with pixels as data you can get the result exactly: test - matrix(c(0, 255), 3, 5) library(rgdal) ## transpose to get orientation right x - image2Grid(list(x = 1:ncol(test), y = 1:nrow(test), z = t(test))) writeGDAL(x, raster.png, driver = PNG, type = Byte) On Mon, Oct 18, 2010 at 3:17 PM, Sharpie ch...@sharpsteen.net wrote: I am working on dumping raster data from R into PNG files using rasterImage(). I am working with a test matrix from the rasterImage() example and using it to produce a PNG image with the following code: # From the example for rasterImage(). A 3 pixel by 5 pixel b/w checkerboard. testImage - as.raster(0:1, nrow=3, ncol=5) testImage [,1] [,2] [,3] [,4] [,5] [1,] #00 #FF #00 #FF #00 [2,] #FF #00 #FF #00 #FF [3,] #00 #FF #00 #FF #00 png('test.png', width=5, height=3, units='px') # Just want the image, no margins, boarders or other fancy stuff. par(mar = c(0,0,0,0) ) plot.new() plotArea = par('fig') rasterImage(testImage, plotArea[1], plotArea[3], plotArea[2], plotArea[4], interpolate = FALSE ) dev.off() However, using R 2.12.0, 64 bit on Windows 7 I have a strange issue where the image is shifted up by one row and to the left by one row. In other words, the bottom row of pixels is missing along with the right column. The code works as I expect it to on OS X and Debian. Am I misusing the plotting commands in some way or should I submit an off-by-one bugreport to Bugzilla? Any suggestions or comments are most welcome. -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://r.789695.n4.nabble.com/Incorrect-positioning-of-raster-images-on-Windows-tp2999649p2999649.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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsum...@gmail.com Hi Micheal, I appreciate the suggestion. However, rgdal is very heavyweight and installing the GDAL library is not a trivial operation automagically handled `install.packages()` on every platform R supports. As I am not doing spatial analysis, I am very reluctant to add rgdal to the dependency list of my package. I would very much prefer to find the root cause of the difference in `png()` behavior on Windows when compared to OS X and Linux. If anyone on this list has some insight to share, I would be very grateful to hear it. I waffled a bit on whether to send this to R-help or R-devel, in the light of day (as opposed to the foggy darkness that surrounds 2am) think it may be more of an R-devel question. Forwarding it there now. -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://r.789695.n4.nabble.com/Incorrect-positioning-of-raster-images-on-Windows-tp2999649p3001166.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.
Re: [R] Question about lme (mixed effects regression)
Dmitri: Not quite sure what you mean by easier ... fixef() and ranef() will both give coefficients which can be easily manipulated to produce the results for all subjects. However, note that there are numerous built-in lme functions(especially for graphics) that do this internally to produce, e.g. graphs of coefficient shrinkage. So if this is the sort of thing you want to do with the BLUPS, you may not need to do it manually. HTH. Cheers, Bert On Mon, Oct 18, 2010 at 2:15 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! If I run this example: library(nlme) fm1 - lme(distance ~ age+Sex, Orthodont, random = ~ age + Sex| Subject) If I run: summary(fm1) then I can see the fixed effects for age and sex (17.7 for intercept, 0.66 for age, and -1.66 for SexFemale) If I run: ranef(fm1) Then it looks like it's producing the random effects for each subgroup (in this example - each subject). For example, for MO1 it's: 1.25 for intercept, 0.106 for age, and -1.52 for SexFemale. So, in order to get the the total effects, i.e., the regression equation, for each subgroup (Subject) I need to do this: For example, for Subject MO1: y(M01) = (17.71+1.25)+(0.66+0.106)*Age+(-1.66-1.52)*SexFemale = 18.96 + 0.766*Age -3.18*SexFemale Question: Is there an easier way to get such an equation for each level of Subject? Thank you very much! -- Dimitri Liakhovitski Ninah Consulting www.ninah.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. -- Bert Gunter Genentech Nonclinical Biostatistics __ 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] Question about lme (mixed effects regression)
Thank you very much, but not I am not sure now - does ranef(fm1) give the (total) slope and intercept values directly for each group or not? Thanks a lot for clarifying - because I might well have been wrong. Dimitri On Mon, Oct 18, 2010 at 5:57 PM, Bert Gunter gunter.ber...@gene.com wrote: Dmitri: Not quite sure what you mean by easier ... fixef() and ranef() will both give coefficients which can be easily manipulated to produce the results for all subjects. However, note that there are numerous built-in lme functions(especially for graphics) that do this internally to produce, e.g. graphs of coefficient shrinkage. So if this is the sort of thing you want to do with the BLUPS, you may not need to do it manually. HTH. Cheers, Bert On Mon, Oct 18, 2010 at 2:15 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! If I run this example: library(nlme) fm1 - lme(distance ~ age+Sex, Orthodont, random = ~ age + Sex| Subject) If I run: summary(fm1) then I can see the fixed effects for age and sex (17.7 for intercept, 0.66 for age, and -1.66 for SexFemale) If I run: ranef(fm1) Then it looks like it's producing the random effects for each subgroup (in this example - each subject). For example, for MO1 it's: 1.25 for intercept, 0.106 for age, and -1.52 for SexFemale. So, in order to get the the total effects, i.e., the regression equation, for each subgroup (Subject) I need to do this: For example, for Subject MO1: y(M01) = (17.71+1.25)+(0.66+0.106)*Age+(-1.66-1.52)*SexFemale = 18.96 + 0.766*Age -3.18*SexFemale Question: Is there an easier way to get such an equation for each level of Subject? Thank you very much! -- Dimitri Liakhovitski Ninah Consulting www.ninah.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. -- Bert Gunter Genentech Nonclinical Biostatistics -- Dimitri Liakhovitski Ninah Consulting www.ninah.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.
Re: [R] Question about lme (mixed effects regression)
Oh -- I get your question (I think). Not the total, just the random effects. You have to add them to the fixed effects. See e.g. p. 39 of Bates and Pinheiro. -- Bert On Mon, Oct 18, 2010 at 3:00 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Thank you very much, but not I am not sure now - does ranef(fm1) give the (total) slope and intercept values directly for each group or not? Thanks a lot for clarifying - because I might well have been wrong. Dimitri On Mon, Oct 18, 2010 at 5:57 PM, Bert Gunter gunter.ber...@gene.com wrote: Dmitri: Not quite sure what you mean by easier ... fixef() and ranef() will both give coefficients which can be easily manipulated to produce the results for all subjects. However, note that there are numerous built-in lme functions(especially for graphics) that do this internally to produce, e.g. graphs of coefficient shrinkage. So if this is the sort of thing you want to do with the BLUPS, you may not need to do it manually. HTH. Cheers, Bert On Mon, Oct 18, 2010 at 2:15 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! If I run this example: library(nlme) fm1 - lme(distance ~ age+Sex, Orthodont, random = ~ age + Sex| Subject) If I run: summary(fm1) then I can see the fixed effects for age and sex (17.7 for intercept, 0.66 for age, and -1.66 for SexFemale) If I run: ranef(fm1) Then it looks like it's producing the random effects for each subgroup (in this example - each subject). For example, for MO1 it's: 1.25 for intercept, 0.106 for age, and -1.52 for SexFemale. So, in order to get the the total effects, i.e., the regression equation, for each subgroup (Subject) I need to do this: For example, for Subject MO1: y(M01) = (17.71+1.25)+(0.66+0.106)*Age+(-1.66-1.52)*SexFemale = 18.96 + 0.766*Age -3.18*SexFemale Question: Is there an easier way to get such an equation for each level of Subject? Thank you very much! -- Dimitri Liakhovitski Ninah Consulting www.ninah.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. -- Bert Gunter Genentech Nonclinical Biostatistics -- Dimitri Liakhovitski Ninah Consulting www.ninah.com -- Bert Gunter Genentech Nonclinical Biostatistics __ 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] Question about lme (mixed effects regression)
Yes, sorry for the confusion. Maybe I should have used a different term. So, I guess, I was right - it gives only the random effects that I have to add to the fixed effects. And there is no way to get it done by R (not that I can't do it myself)? Dimitri On Mon, Oct 18, 2010 at 6:24 PM, Bert Gunter gunter.ber...@gene.com wrote: Oh -- I get your question (I think). Not the total, just the random effects. You have to add them to the fixed effects. See e.g. p. 39 of Bates and Pinheiro. -- Bert On Mon, Oct 18, 2010 at 3:00 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Thank you very much, but not I am not sure now - does ranef(fm1) give the (total) slope and intercept values directly for each group or not? Thanks a lot for clarifying - because I might well have been wrong. Dimitri On Mon, Oct 18, 2010 at 5:57 PM, Bert Gunter gunter.ber...@gene.com wrote: Dmitri: Not quite sure what you mean by easier ... fixef() and ranef() will both give coefficients which can be easily manipulated to produce the results for all subjects. However, note that there are numerous built-in lme functions(especially for graphics) that do this internally to produce, e.g. graphs of coefficient shrinkage. So if this is the sort of thing you want to do with the BLUPS, you may not need to do it manually. HTH. Cheers, Bert On Mon, Oct 18, 2010 at 2:15 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! If I run this example: library(nlme) fm1 - lme(distance ~ age+Sex, Orthodont, random = ~ age + Sex| Subject) If I run: summary(fm1) then I can see the fixed effects for age and sex (17.7 for intercept, 0.66 for age, and -1.66 for SexFemale) If I run: ranef(fm1) Then it looks like it's producing the random effects for each subgroup (in this example - each subject). For example, for MO1 it's: 1.25 for intercept, 0.106 for age, and -1.52 for SexFemale. So, in order to get the the total effects, i.e., the regression equation, for each subgroup (Subject) I need to do this: For example, for Subject MO1: y(M01) = (17.71+1.25)+(0.66+0.106)*Age+(-1.66-1.52)*SexFemale = 18.96 + 0.766*Age -3.18*SexFemale Question: Is there an easier way to get such an equation for each level of Subject? Thank you very much! -- Dimitri Liakhovitski Ninah Consulting www.ninah.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. -- Bert Gunter Genentech Nonclinical Biostatistics -- Dimitri Liakhovitski Ninah Consulting www.ninah.com -- Bert Gunter Genentech Nonclinical Biostatistics -- Dimitri Liakhovitski Ninah Consulting www.ninah.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.
Re: [R] read.spss warning message (Unrecognized record type 7, subtype 18 encountered in system file)
If you do a search of the archives you will find several similar questions. As far as I know the answer has generally been unavailable. It is after all only a warning and you should have gotten uesful material in the returned value. -- David. On Oct 18, 2010, at 2:16 PM, Paul Miller wrote: Hello Everyone, Trying to help someone recover the contents of an SPSS.sav file using read.spss. This seemed to work well but produced a warning message. My code and the warning are displayed below. Spent some time looking for previous questions about this warning. Found a lot of questions posted but wasn't able to figure out what the problem is. Is there anyone out there who can explain what's going wrong and how I can fix it? Thanks, Paul dataSPSS-read.spss(N:/Mark.sav,to.data.frame = TRUE) Warning message: In read.spss(N:/Mark.sav, to.data.frame = TRUE) : N:/Mark.sav: Unrecognized record type 7, subtype 18 encountered in system file View(dataSPSS) write.csv(dataSPSS,N:/Mark.csv) [[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. David Winsemius, MD West Hartford, CT __ 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] Extracting elements from a nested list
Does this do what you want: x - lapply(seq_along(MaxGrowth), function(.num){ + AllPredictedValues[[.num]][[MaxGrowth[[.num + }) x [[1]] [1] 2 1 2 2 2 2 0 2 2 0 0 2 2 0 0 2 2 1 2 0 1 1 0 0 0 2 0 0 0 2 2 0 0 1 0 0 2 0 1 0 2 0 0 2 1 0 0 0 2 1 0 2 2 [54] 2 2 0 2 0 1 0 2 0 1 0 0 0 1 0 0 2 2 2 2 2 2 1 0 2 0 2 0 0 0 0 2 0 2 1 2 2 0 2 0 0 0 0 1 2 2 1 Levels: 0 1 2 [[2]] [1] 0 1 0 1 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [54] 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 Levels: 0 1 2 [[3]] [1] 2 0 2 0 2 2 0 2 0 0 0 2 2 1 0 2 2 0 2 0 1 1 0 0 0 0 0 0 0 2 2 0 0 1 0 0 2 0 1 0 2 0 0 2 0 1 1 0 2 1 0 2 2 [54] 2 2 0 2 0 0 0 2 0 0 0 0 0 0 1 0 2 2 2 2 2 2 0 0 2 0 2 0 0 0 1 0 0 2 0 2 2 0 2 0 0 0 0 0 2 2 1 Levels: 0 1 2 On Mon, Oct 18, 2010 at 5:36 PM, Gregory Ryslik rsa...@comcast.net wrote: Hi, It seems that the files did not make it through the mailer. Perhaps it didn't like my extensions. I have now attached the files as .txt's as well as copied in the contents of each file: MaxGrowth.txt: list(4L, 3L, 4L) AllPredictedValues.txt list(list(structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0, 1, 2), class = factor), structure(c(3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L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, 2L, 2L, 2L), .Label = c(0, 1, 2), class = factor), structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L), .Label = c(0, 1, 2), class = factor)), list( structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0, 1, 2), class = factor), structure(c(3L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 2L, 2L,
[R] help - RE: Download.file problem
Dear R-helpers ... any thoughts on the below issue ... will help me complete a small project! Strange problem with download.file . for non existent URL an empty file is created but I am not able to delete the without shutting down R Example: download.file(http://test.com/test.txt,test.txt;) trying URL 'http://test.com/test.txt' Error in download.file(http://test.com/test.txt;, test.txt) : cannot open URL 'http://test.com/test.txt' In addition: Warning message: In download.file(http://test.com/test.txt;, test.txt) : cannot open: HTTP status was '404 Not Found' If you go to working directory through windows explorer, you can see the empty file test.txt but try deleteting the file and it says that the file is locked. I tried closeAllConnections() but of no use. Any suggestions? Thanks, S __ 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] help - RE: Download.file problem
On 18/10/2010 8:34 PM, Santosh Srinivas wrote: Dear R-helpers ... any thoughts on the below issue ... will help me complete a small project! Strange problem with download.file . for non existent URL an empty file is created but I am not able to delete the without shutting down R Example: download.file(http://test.com/test.txt,test.txt;) trying URL 'http://test.com/test.txt' Error in download.file(http://test.com/test.txt;, test.txt) : cannot open URL 'http://test.com/test.txt' In addition: Warning message: In download.file(http://test.com/test.txt;, test.txt) : cannot open: HTTP status was '404 Not Found' If you go to working directory through windows explorer, you can see the empty file test.txt but try deleteting the file and it says that the file is locked. I tried closeAllConnections() but of no use. Any suggestions? Suggestion: Don't try to download a nonexistent file to a filename that you care about. It looks like a bug in download.file is leaving the file open; Windows won't let you delete open files. So you could download to tempfile() first to see if it works; if that fails, you'll be left with a junk file open, but it will be closed when R quits. If you want to help, you could look through the internal code to figure out why the file isn't being closed, and submit a patch. 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] Randomly shuffle an array 1000 times
Hi: One way to permute your sample 1000 times is to use the r*ply() function from the plyr package. Let s denote your original vector, randomly generated as follows: s - rbinom(800, 0.6) # simulates your Yes/No vector library(plyr) u - raply(1000, sample(s))# generates a 1000 x 800 matrix As Steve mentioned, you can also use replicate(): v - replicate(1000, sample(r)) # generates an 800 x 1000 matrix # With mydata as your original data frame, the 1000 reshuffles can be attached with df - data.frame(mydata, t(u)) # or df - data.frame(mydata, v) names(df)[3:1002] - paste('S', 1:1000, sep = '') write.csv(df, file = 'myExcelFile.csv', quote = FALSE, row.names = FALSE) Substitute your input vector for s in the raply() call. [Note that replicate() is about 10 times faster than raply() for this example.] The result should be an 800 x 1002 (two original variables + 1000 reshuffles) data frame. Writing to a csv file is a convenient intermediary between R and Excel, but there are several ways to write data from R to Excel. See http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows HTH, Dennis On Mon, Oct 18, 2010 at 4:37 AM, Peter Francis peterfran...@me.com wrote: Dear List, I have a table i have read into R: NameYes/No John0 Frank 1 Ann 0 James 1 Alex1 etc - 800 different times. What i want to do is shuffle yes/no and randomly re-assign them to the name. I have used sample() and permute(), however there is no way to do this 1000 times. Furthermore, i want to copy the data into a excel spreadsheet in the same order as the data was input so i can build up a distribution of the statistic for each name. When i use shuffle the date gets returned like this - [1] 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1 [34] 0 1 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 [67] 0 0 0 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 [100] 1 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 [133] 0 0 0 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 [166] 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 0 1 [199] 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 [232] 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 [265] 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 [298] 0 1 1 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 0 [331] 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 etc Rather than like this John0 Frank 1 Ann 0 James 1 Alex1 Can anyone suggest a script that would achieve this? Thanks Peter __ 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. [[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.