[R] interfacing with .Call
Hi My code is as following: #include R.h #include Rinternals.h //* the Projector part *// void Projector(double *L, int *dimL, double *G, int *dimG, double *W, int *dimW, int *xymod, int *dimxy, double *modif, int *dimif, double *Lsum) { ...} //* the interface part *// #define getDim(A) INTEGER(coerceVector(getAttrib(A,R_DimSymbol), INTSXP)) SEXP Projector5(SEXP L, SEXP G, SEXP W, SEXP xymod, SEXP modif) { //* digest SEXPs from R *// int *dimL, *dimG, *dimW, *dimxy, *dimif; double *lptr, *gptr, *wptr, *ifptr; int *xyptr; dimL=getDim(L); PROTECT(L=coerceVector(L, REALSXP)); lptr=REAL(L); dimG=getDim(G); PROTECT(G=coerceVector(G, REALSXP)); gptr=REAL(G); dimW=getDim(W); PROTECT(W=coerceVector(W, REALSXP)); wptr=REAL(W); dimxy=getDim(xymod); PROTECT(xymod=coerceVector(xymod, INTSXP)); xyptr=INTEGER(xymod); dimif=getDim(modif); PROTECT(modif=coerceVector(modif, REALSXP)); ifptr=REAL(modif); //* create SEXP to hold the answer *// SEXP ans; double *ansptr; PROTECT(ans=allocMatrix(REALSXP, dimG[1], dimG[0])); ansptr=REAL(ans); //* calculate the result *// Projector(lptr, dimL, gptr, dimG, wptr, dimW, xyptr, dimxy, ifptr, dimif, ansptr); //* wrap up and return the result to R *// UNPROTECT(6); return(ans); } The function Projector works well and actually the interface with .C works OK. The question is that I can compile it in R, but .Call returns different result each time with same inputs. Could anybody tell me why? Thanks! Regards Shangru -- Department of Mathematics, National University of Singapore, Blk S17, 10 Lower Kent Ridge Road, 119076 [[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] kruskalmc, significant differences while median values are the same
Dear list! I work with multiple Kruskal-Wallis test (kruskalmc, package pgirmess), which evaluates differences in medians among groups (5 groups). A result of a test is significant differences among some groups, while median values are the same for 4 groups (using tapply). Why? p.s.: number of samples in groups vary from 50 to 4900. Thanks to all, OV . __ 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] kruskalmc, significant differences while median values are the same
Hello, What about the median ranks? This test is based on ranks. Regards, Pascal Le 12/12/15 18:04, Omphalodes Verna a écrit : Dear list! I work with multiple Kruskal-Wallis test (kruskalmc, package pgirmess), which evaluates differences in medians among groups (5 groups). A result of a test is significant differences among some groups, while median values are the same for 4 groups (using tapply). Why? p.s.: number of samples in groups vary from 50 to 4900. Thanks to all, OV . __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to speed up the for loop by releasing memeory
Dear list; How can I speed up the run of following code (illustrative) # con-vector(numeric) for (i in 1:limit) { if(matched data for the ith item found) { if(i==1) {con-RowOfMatchedData } else {con-rbind(con,matchedData)} } } # each RowOfMatchedData contains 105 variables, when i runs over 10^7 and the data container con get large enough, the codes get extremely slow, I know this is a working memory problem (2GB only), is there anyway to circumvent this problem without dicing and slicing the data. __ 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] format.pval () and printCoefmat ()
Dear Arun and David, I am so grateful to you for all your help with the code. Thanks and regards, Pradip Arun - All this is very helpful. In general, I can follow the code. I only have the following questions: What changes in the code would be required to have 3 places after decimal for all numeric variables in the res data frame? Thanks, Pradip ### below is the display of the data from Lines1, Lines2, and res head (data.frame(Lines1)) Lines1 1mean_level1 mean_level2 rel_diff p_mean cohens_d 2 1 18.744 11.9110.574 0.000.175 3 2 18.744 14.4550.297 0.000.110 4 3 18.744 13.5400.384 0.000.133 5 4 18.744 6.0022.123 0.000.333 6 5 18.744 5.8342.213 0.000.349 head (data.frame(Lines2)) Lines2 1mean_level1 mean_level2 rel_diff p_mean cohens_d 2 1 18.744 11.9110.574 0.000.175 3 2 18.744 14.4550.297 0.000.110 4 3 18.744 13.5400.384 0.000.133 5 4 18.744 6.0022.123 0.000.333 6 5 18.744 5.8342.213 0.000.349 head (res) contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diff p_mean cohens_d 1 wh2+hi18.7 11.910.574 0 0.175 2 wh2+rc18.7 14.460.297 0 0.110 3 whaian18.7 13.540.384 0 0.133 4 whasan18.76.002.123 0 0.333 5 whblck18.75.832.213 0 0.349 6 whcsam18.77.931.363 0 0.279 From: arun [smartpink...@yahoo.com] Sent: Friday, December 14, 2012 10:12 PM To: Muhuri, Pradip (SAMHSA/CBHSQ) Cc: R help; David Winsemius Subject: Re: [R] format.pval () and printCoefmat () Hi Pradip, May be this helps: dat1-read.table(text= contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diffp_mean cohens_d 1 wh2+hi18.7 11.910.574 1.64e-05 0.1753 2 wh2+rc18.7 14.460.297 9.24e-06 0.1101 3 whaian18.7 13.540.384 9.01e-05 0.1335 4 whasan18.76.002.123 2.20e-119 0.3326 5 whblck18.75.832.213 0.00e+00 0.3490 6 whcsam18.77.931.363 1.27e-47 0.2793 7 whcub18.7 10.850.728 6.12e-08 0.2025 8 whdmcn18.77.131.629 1.59e-15 0.2981 9 whhisp18.79.720.928 3.27e-125 0.2420 10 whmex18.79.600.952 8.81e-103 0.2420 11 whnhpi18.7 16.140.162 1.74e-01 0.0669 12 whothh18.7 NA NANA NA 13 wh pr18.7 10.470.791 3.64e-23 0.2131 14 whspn18.7 15.150.237 1.58e-02 0.0922 ,sep=,header=TRUE,stringsAsFactors=FALSE) Lines1-capture.output(printCoefmat(dat1[,-c(1:2)],has.Pvalue=TRUE,eps.Pvalue=0.001)) Lines2-gsub(\\s+$,,gsub(\\.$,,Lines1[1:15])) res-data.frame(dat1[,1:2],read.table(text=Lines2,header=TRUE)) #or # res-cbind(dat1[,1:2],read.table(text=Lines2,header=TRUE)) res # contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diff p_mean #1 wh2+hi18.7 11.910.574 0. #2 wh2+rc18.7 14.460.297 0. #3 whaian18.7 13.540.384 0.0001 - -- # cohens_d #10.1753 #20.1101 #30.1335 - - str(res) #'data.frame':14 obs. of 7 variables: # $ contrast_level1: chr wh wh wh wh ... # $ contrast_level2: chr 2+hi 2+rc aian asan ... # $ mean_level1: num 18.7 18.7 18.7 18.7 18.7 18.7 18.7 18.7 18.7 18.7 ... # $ mean_level2: num 11.91 14.46 13.54 6 5.83 ... # $ rel_diff : num 0.574 0.297 0.384 2.123 2.213 ... # $ p_mean : num 0e+00 0e+00 1e-04 0e+00 0e+00 0e+00 0e+00 0e+00 0e+00 0e+00 ... # $ cohens_d : num 0.175 0.11 0.134 0.333 0.349 ... A.K. - Original Message - From: Muhuri, Pradip (SAMHSA/CBHSQ) pradip.muh...@samhsa.hhs.gov To: 'David Winsemius' dwinsem...@comcast.net Cc: R help r-help@r-project.org Sent:
Re: [R] How to speed up the for loop by releasing memeory
Please read the posting guide. You need to provide reproducible code (please simplify, but make sure it illustrates your problem and runs) to communicate clearly what problem you are trying to solve. Chances are good that you don't need any for loop at all, but without running code we can't tell. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Yong Wang wangyo...@gmail.com wrote: Dear list; How can I speed up the run of following code (illustrative) # con-vector(numeric) for (i in 1:limit) { if(matched data for the ith item found) { if(i==1) {con-RowOfMatchedData } else {con-rbind(con,matchedData)} } } # each RowOfMatchedData contains 105 variables, when i runs over 10^7 and the data container con get large enough, the codes get extremely slow, I know this is a working memory problem (2GB only), is there anyway to circumvent this problem without dicing and slicing the data. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to limit string size when displaying data frames?
Hello, Is there a way to set the maximum width of character columns when printing a data frame? I've looked into print(), format(), and options() and have been unsuccessful. For example, I'd like to achieve the results below without having to modify the data itself. x - data.frame(c1=rnorm(5), c2=ABCDEFGHIJKLMNOPQRSTUVWXYZ) x c1 c2 1 0.7076495 ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 -0.1572245 ABCDEFGHIJKLMNOPQRSTUVWXYZ 3 0.3515308 ABCDEFGHIJKLMNOPQRSTUVWXYZ 4 0.3492925 ABCDEFGHIJKLMNOPQRSTUVWXYZ 5 -0.3805869 ABCDEFGHIJKLMNOPQRSTUVWXYZ x$c2 - substr(x$c2, 1, 10) #Only show first 10 chars. x c1 c2 1 0.7076495 ABCDEFGHIJ 2 -0.1572245 ABCDEFGHIJ 3 0.3515308 ABCDEFGHIJ 4 0.3492925 ABCDEFGHIJ 5 -0.3805869 ABCDEFGHIJ Thanks, Mauricio [[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] How to speed up the for loop by releasing memeory
On 12-12-15 10:10 AM, Yong Wang wrote: Dear list; How can I speed up the run of following code (illustrative) # con-vector(numeric) for (i in 1:limit) { if(matched data for the ith item found) { if(i==1) {con-RowOfMatchedData } else {con-rbind(con,matchedData)} } } # each RowOfMatchedData contains 105 variables, when i runs over 10^7 and the data container con get large enough, the codes get extremely slow, I know this is a working memory problem (2GB only), is there anyway to circumvent this problem without dicing and slicing the data. You are reallocating and copying con in every step in your loop. Preallocate it and just assign new data into the appropriate row and things will be much faster. 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] How to limit string size when displaying data frames?
On Dec 15, 2012, at 8:27 AM, Mauricio Cornejo wrote: Hello, Is there a way to set the maximum width of character columns when printing a data frame? I've looked into print(), format(), and options() and have been unsuccessful. For example, I'd like to achieve the results below without having to modify the data itself. data.frame(lapply(x, substr, 1, 10)) c1 c2 1 0.13891058 ABCDEFGHIJ 2 -0.0533631 ABCDEFGHIJ 3 -0.9799945 ABCDEFGHIJ 4 0.44754950 ABCDEFGHIJ 5 0.90906556 ABCDEFGHIJ x - data.frame(c1=rnorm(5), c2=ABCDEFGHIJKLMNOPQRSTUVWXYZ) x c1 c2 1 0.7076495 ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 -0.1572245 ABCDEFGHIJKLMNOPQRSTUVWXYZ 3 0.3515308 ABCDEFGHIJKLMNOPQRSTUVWXYZ 4 0.3492925 ABCDEFGHIJKLMNOPQRSTUVWXYZ 5 -0.3805869 ABCDEFGHIJKLMNOPQRSTUVWXYZ x$c2 - substr(x$c2, 1, 10) #Only show first 10 chars. x c1 c2 1 0.7076495 ABCDEFGHIJ 2 -0.1572245 ABCDEFGHIJ 3 0.3515308 ABCDEFGHIJ 4 0.3492925 ABCDEFGHIJ 5 -0.3805869 ABCDEFGHIJ Thanks, Mauricio [[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 Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to run MCMC with binomial distribution
Hello, could you tell me how to run a MCMC with binomial distribution? If there is an example will be nice to know about it. Thanks, Tania [[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] Installing Packages from a Local Repository
You have to specify the repository as file:Q:/Integrated Planning/R (and I am not entirely sure if blanks are supported). Best, Uwe Ligges On 13.12.2012 11:52, Tommy O'Dell wrote: Hi everyone, I've followed the instructions from R-Admin Section 6.6 for creating a local repository. I've modified my Rprofile.site file to add the local repository to my repos, but I haven't been able to successfully install my package from the repo. Here's the code that I've run. ## sessionInfo() getOption(repos) setwd(Q:/Integrated Planning/R) list.files(path = ., recursive = TRUE) tools::write_PACKAGES(bin/windows/contrib/2.15, type = win.binary) list.files(path = ., recursive = TRUE) install.packages(RTIO) install.packages(RTIO, repos = Q:/Integrated Planning/R) install.packages(RTIO, repos = Q:/Integrated Planning/R, type = win.binary) unlink(c(bin/windows/contrib/2.15/PACKAGES,bin/windows/contrib/2.15/PACKAGES.gz)) And here it is with output included: ### sessionInfo() R version 2.15.1 (2012-06-22) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252 LC_NUMERIC=C LC_TIME=English_Australia.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.1 getOption(repos) CRANCRANextra MyLocal http://cran.ms.unimelb.edu.au/; http://www.stats. ox.ac.uk/pub/RWin file://Q:/Integrated Planning/R setwd(Q:/Integrated Planning/R) list.files(path = ., recursive = TRUE) [1] bin/windows/contrib/2.15/RTIO_0.1-2.zip tools::write_PACKAGES(bin/windows/contrib/2.15, type = win.binary) list.files(path = ., recursive = TRUE) [1] bin/windows/contrib/2.15/PACKAGES bin/windows/contrib/2.15/PACKAGES.gz bin/windows/contrib/2.15/RTIO_0.1-2.zip install.packages(RTIO) Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’ (as ‘lib’ is unspecified) Warning in install.packages : cannot open compressed file '//Q:/Integrated Planning/R/bin/windows/contrib/2.15/PACKAGES', probable reason 'No such file or directory' Error in install.packages : cannot open the connection install.packages(RTIO, repos = Q:/Integrated Planning/R) Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’ (as ‘lib’ is unspecified) Warning in install.packages : unable to access index for repository Q:/Integrated Planning/R/bin/windows/contrib/2.15 Warning in install.packages : package ‘RTIO’ is not available (for R version 2.15.1) install.packages(RTIO, repos = Q:/Integrated Planning/R, type = win.binary) Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’ (as ‘lib’ is unspecified) Warning in install.packages : unable to access index for repository Q:/Integrated Planning/R/bin/windows/contrib/2.15 Warning in install.packages : package ‘RTIO’ is not available (for R version 2.15.1) unlink(c(bin/windows/contrib/2.15/PACKAGES,bin/windows/contrib/2.15/PACKAGES.gz)) ### I'd really like to be able to use install.packages(RTIO) without having to specify the repo, as this will make it easy for our other less experienced R users. Any ideas why I get warning: cannot open compressed file and error: cannot open the connection? As far as I can tell, I've followed the R-Admin 6.6 instructions exactly. If it matters, Q: is a mapped network drive. [[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] Installing Packages from a Local Repository
On 15/12/2012 17:36, Uwe Ligges wrote: You have to specify the repository as file:Q:/Integrated Planning/R (and I am not entirely sure if blanks are supported). Actually, that's not right: see ?url. All URI schemes start like file:// . For Windows the help says In this form the path is relative to the root of the filesystem, not a Windows concept. The standard form on Windows is ‘file:///d:/R/repos’: for compatibility with earlier versions of R and Unix versions, any other form is parsed as R as ‘file://’ plus ‘path_to_file’. Also, backslashes are accepted within the path even though RFC1738 does not allow them. Spaces should work, since it is R which converts this to a filepath (in a real URI there are lots of restrictions and spaces need to be encoded if the restrictions are enforced). But file:// URIs on Windows are a minefield. Best, Uwe Ligges On 13.12.2012 11:52, Tommy O'Dell wrote: Hi everyone, I've followed the instructions from R-Admin Section 6.6 for creating a local repository. I've modified my Rprofile.site file to add the local repository to my repos, but I haven't been able to successfully install my package from the repo. Here's the code that I've run. ## sessionInfo() getOption(repos) setwd(Q:/Integrated Planning/R) list.files(path = ., recursive = TRUE) tools::write_PACKAGES(bin/windows/contrib/2.15, type = win.binary) list.files(path = ., recursive = TRUE) install.packages(RTIO) install.packages(RTIO, repos = Q:/Integrated Planning/R) install.packages(RTIO, repos = Q:/Integrated Planning/R, type = win.binary) unlink(c(bin/windows/contrib/2.15/PACKAGES,bin/windows/contrib/2.15/PACKAGES.gz)) And here it is with output included: ### sessionInfo() R version 2.15.1 (2012-06-22) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252 LC_NUMERIC=C LC_TIME=English_Australia.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.1 getOption(repos) CRAN CRANextra MyLocal http://cran.ms.unimelb.edu.au/; http://www.stats. ox.ac.uk/pub/RWin file://Q:/Integrated Planning/R setwd(Q:/Integrated Planning/R) list.files(path = ., recursive = TRUE) [1] bin/windows/contrib/2.15/RTIO_0.1-2.zip tools::write_PACKAGES(bin/windows/contrib/2.15, type = win.binary) list.files(path = ., recursive = TRUE) [1] bin/windows/contrib/2.15/PACKAGES bin/windows/contrib/2.15/PACKAGES.gz bin/windows/contrib/2.15/RTIO_0.1-2.zip install.packages(RTIO) Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’ (as ‘lib’ is unspecified) Warning in install.packages : cannot open compressed file '//Q:/Integrated Planning/R/bin/windows/contrib/2.15/PACKAGES', probable reason 'No such file or directory' Error in install.packages : cannot open the connection install.packages(RTIO, repos = Q:/Integrated Planning/R) Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’ (as ‘lib’ is unspecified) Warning in install.packages : unable to access index for repository Q:/Integrated Planning/R/bin/windows/contrib/2.15 Warning in install.packages : package ‘RTIO’ is not available (for R version 2.15.1) install.packages(RTIO, repos = Q:/Integrated Planning/R, type = win.binary) Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’ (as ‘lib’ is unspecified) Warning in install.packages : unable to access index for repository Q:/Integrated Planning/R/bin/windows/contrib/2.15 Warning in install.packages : package ‘RTIO’ is not available (for R version 2.15.1) unlink(c(bin/windows/contrib/2.15/PACKAGES,bin/windows/contrib/2.15/PACKAGES.gz)) ### I'd really like to be able to use install.packages(RTIO) without having to specify the repo, as this will make it easy for our other less experienced R users. Any ideas why I get warning: cannot open compressed file and error: cannot open the connection? As far as I can tell, I've followed the R-Admin 6.6 instructions exactly. If it matters, Q: is a mapped network drive. [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of
Re: [R] format.pval () and printCoefmat ()
Hi Arun, Thank you so much for further clarifications and help. Pradip Pradip K. Muhuri, PhD Statistician Substance Abuse Mental Health Services Administration The Center for Behavioral Health Statistics and Quality Division of Population Surveys 1 Choke Cherry Road, Room 2-1071 Rockville, MD 20857 Tel: 240-276-1070 Fax: 240-276-1260 e-mail: pradip.muh...@samhsa.hhs.gov The Center for Behavioral Health Statistics and Quality your feedback. Please click on the following link to complete a brief customer survey: http://cbhsqsurvey.samhsa.gov -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Saturday, December 15, 2012 11:04 AM To: Muhuri, Pradip (SAMHSA/CBHSQ) Cc: R help; David Winsemius Subject: Re: [R] format.pval () and printCoefmat () Hi Pradip, It this is just formatting issue, it is possible to do that with ?formatC() or ?sprintf(), but it may change those variables from numeric to character. One possibilty from `res`: res-data.frame(dat1[,1:2],read.table(text=Lines2,header=TRUE)) varsNum-sapply(res,is.numeric) res[varsNum]-lapply(res[varsNum],round,digits=3) #Here, the numeric columns with digits3 are not changed, but the ones with 3 were all changed to digits3. As I mentioned, sprintf() changes the number of digits as.data.frame(do.call(cbind,lapply(res[varsNum],function(x) sprintf(%.3f,x # mean_level1 mean_level2 rel_diff p_mean cohens_d #1 18.700 11.9100.574 0.0000.175 #2 18.700 14.4600.297 0.0000.110 #3 18.700 13.5400.384 0.0000.134 A.K. - Original Message - From: Muhuri, Pradip (SAMHSA/CBHSQ) pradip.muh...@samhsa.hhs.gov To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; David Winsemius dwinsem...@comcast.net Sent: Saturday, December 15, 2012 10:12 AM Subject: RE: [R] format.pval () and printCoefmat () Dear Arun and David, I am so grateful to you for all your help with the code. Thanks and regards, Pradip Arun - All this is very helpful. In general, I can follow the code. I only have the following questions: What changes in the code would be required to have 3 places after decimal for all numeric variables in the res data frame? Thanks, Pradip ### below is the display of the data from Lines1, Lines2, and res head (data.frame(Lines1)) Lines1 1mean_level1 mean_level2 rel_diff p_mean cohens_d 2 1 18.744 11.9110.574 0.000.175 3 2 18.744 14.4550.297 0.000.110 4 3 18.744 13.5400.384 0.000.133 5 4 18.744 6.0022.123 0.000.333 6 5 18.744 5.8342.213 0.000.349 head (data.frame(Lines2)) Lines2 1mean_level1 mean_level2 rel_diff p_mean cohens_d 2 1 18.744 11.9110.574 0.000.175 3 2 18.744 14.4550.297 0.000.110 4 3 18.744 13.5400.384 0.000.133 5 4 18.744 6.0022.123 0.000.333 6 5 18.744 5.8342.213 0.000.349 head (res) contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diff p_mean cohens_d 1 wh2+hi18.7 11.910.574 0 0.175 2 wh2+rc18.7 14.460.297 0 0.110 3 whaian18.7 13.540.384 0 0.133 4 whasan18.76.002.123 0 0.333 5 whblck18.75.832.213 0 0.349 6 whcsam18.77.931.363 0 0.279 From: arun [smartpink...@yahoo.com] Sent: Friday, December 14, 2012 10:12 PM To: Muhuri, Pradip (SAMHSA/CBHSQ) Cc: R help; David Winsemius Subject: Re: [R] format.pval () and printCoefmat () Hi Pradip, May be this helps: dat1-read.table(text= contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diffp_mean cohens_d 1 wh2+hi18.7 11.910.574 1.64e-05 0.1753 2 wh2+rc18.7 14.460.297 9.24e-06 0.1101 3 whaian18.7 13.540.384 9.01e-05 0.1335 4 whasan18.76.002.123 2.20e-119 0.3326 5 whblck18.75.832.213 0.00e+00 0.3490 6 whcsam18.77.931.363 1.27e-47 0.2793 7 whcub18.7 10.850.728 6.12e-08 0.2025 8 whdmcn18.77.131.629 1.59e-15 0.2981 9 whhisp18.79.720.928 3.27e-125 0.2420 10 whmex18.79.600.952 8.81e-103 0.2420 11 whnhpi
[R] Problem when plotting
Hi, I was trying to call chart.Posn. I ran into an unusual problem. It complains that: Error in strheight(axt): X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*..., face 1 at size 11 could not be loaded. I am wondering how to fix this? It seems something is missing from X11 device but I don't know what exactly to install. Thank you. Robert [[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] How to speed up the for loop by releasing memeory
You are in Circle 2 of 'The R Inferno'. You are wise to want to leave. http://www.burns-stat.com/pages/Tutor/R_inferno.pdf Pat On 15/12/2012 15:10, Yong Wang wrote: Dear list; How can I speed up the run of following code (illustrative) # con-vector(numeric) for (i in 1:limit) { if(matched data for the ith item found) { if(i==1) {con-RowOfMatchedData } else {con-rbind(con,matchedData)} } } # each RowOfMatchedData contains 105 variables, when i runs over 10^7 and the data container con get large enough, the codes get extremely slow, I know this is a working memory problem (2GB only), is there anyway to circumvent this problem without dicing and slicing the data. __ 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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ 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 limit string size when displaying data frames?
David ... thank you. OK ... so it appears there's no direct way to do this. But I could write a function for printing data frames that would utilize your suggested approach, data.frame(lapply()). This way, I could simply call the function with the data frame object as the argument. Thanks again for the idea. Mauricio From: David Winsemius dwinsem...@comcast.net Cc: r-help@r-project.org r-help@r-project.org Sent: Saturday, December 15, 2012 11:48 AM Subject: Re: [R] How to limit string size when displaying data frames? On Dec 15, 2012, at 8:27 AM, Mauricio Cornejo wrote: Hello, Is there a way to set the maximum width of character columns when printing a data frame? I've looked into print(), format(), and options() and have been unsuccessful. For example, I'd like to achieve the results below without having to modify the data itself. data.frame(lapply(x, substr, 1, 10)) c1 c2 1 0.13891058 ABCDEFGHIJ 2 -0.0533631 ABCDEFGHIJ 3 -0.9799945 ABCDEFGHIJ 4 0.44754950 ABCDEFGHIJ 5 0.90906556 ABCDEFGHIJ x - data.frame(c1=rnorm(5), c2=ABCDEFGHIJKLMNOPQRSTUVWXYZ) x c1 c2 1 0.7076495 ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 -0.1572245 ABCDEFGHIJKLMNOPQRSTUVWXYZ 3 0.3515308 ABCDEFGHIJKLMNOPQRSTUVWXYZ 4 0.3492925 ABCDEFGHIJKLMNOPQRSTUVWXYZ 5 -0.3805869 ABCDEFGHIJKLMNOPQRSTUVWXYZ x$c2 - substr(x$c2, 1, 10) #Only show first 10 chars. x c1 c2 1 0.7076495 ABCDEFGHIJ 2 -0.1572245 ABCDEFGHIJ 3 0.3515308 ABCDEFGHIJ 4 0.3492925 ABCDEFGHIJ 5 -0.3805869 ABCDEFGHIJ Thanks, Mauricio [[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 Alameda, CA, USA [[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] How to limit string size when displaying data frames?
In creating that function, you may want to skip numeric fields so they do not get trimmed: trimstr - function(x, len=10) { if (is.numeric(x)) +x else substr(x, 1, len) + } x c1 c2 1 -0.1674062 ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 2.1589942 ABCDEFGHIJKLMNOPQRSTUVWXYZ 3 -0.8040007 ABCDEFGHIJKLMNOPQRSTUVWXYZ 4 -0.9700669 ABCDEFGHIJKLMNOPQRSTUVWXYZ 5 0.8085148 ABCDEFGHIJKLMNOPQRSTUVWXYZ data.frame(lapply(x, trimstr)) c1 c2 1 -0.1674062 ABCDEFGHIJ 2 2.1589942 ABCDEFGHIJ 3 -0.8040007 ABCDEFGHIJ 4 -0.9700669 ABCDEFGHIJ 5 0.8085148 ABCDEFGHIJ data.frame(lapply(x, trimstr, len=4)) c1 c2 1 -0.1674062 ABCD 2 2.1589942 ABCD 3 -0.8040007 ABCD 4 -0.9700669 ABCD 5 0.8085148 ABCD -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Mauricio Cornejo Sent: Saturday, December 15, 2012 3:16 PM To: David Winsemius Cc: r-help@r-project.org Subject: Re: [R] How to limit string size when displaying data frames? David ... thank you. OK ... so it appears there's no direct way to do this. But I could write a function for printing data frames that would utilize your suggested approach, data.frame(lapply()). This way, I could simply call the function with the data frame object as the argument. Thanks again for the idea. Mauricio From: David Winsemius dwinsem...@comcast.net Cc: r-help@r-project.org r-help@r-project.org Sent: Saturday, December 15, 2012 11:48 AM Subject: Re: [R] How to limit string size when displaying data frames? On Dec 15, 2012, at 8:27 AM, Mauricio Cornejo wrote: Hello, Is there a way to set the maximum width of character columns when printing a data frame? I've looked into print(), format(), and options() and have been unsuccessful. For example, I'd like to achieve the results below without having to modify the data itself. data.frame(lapply(x, substr, 1, 10)) c1 c2 1 0.13891058 ABCDEFGHIJ 2 -0.0533631 ABCDEFGHIJ 3 -0.9799945 ABCDEFGHIJ 4 0.44754950 ABCDEFGHIJ 5 0.90906556 ABCDEFGHIJ x - data.frame(c1=rnorm(5), c2=ABCDEFGHIJKLMNOPQRSTUVWXYZ) x c1 c2 1 0.7076495 ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 -0.1572245 ABCDEFGHIJKLMNOPQRSTUVWXYZ 3 0.3515308 ABCDEFGHIJKLMNOPQRSTUVWXYZ 4 0.3492925 ABCDEFGHIJKLMNOPQRSTUVWXYZ 5 -0.3805869 ABCDEFGHIJKLMNOPQRSTUVWXYZ x$c2 - substr(x$c2, 1, 10) #Only show first 10 chars. x c1 c2 1 0.7076495 ABCDEFGHIJ 2 -0.1572245 ABCDEFGHIJ 3 0.3515308 ABCDEFGHIJ 4 0.3492925 ABCDEFGHIJ 5 -0.3805869 ABCDEFGHIJ Thanks, Mauricio [[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 Alameda, CA, USA [[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] Single node in tree
Hi there, I'm new to R and need some help. I have a dataset of 30,000 records with a response (1/0) indicator resulting in a response rate of 29%. I have 1 categorical predictor variable (gender - M/F) and two continuous variables (score and age). When I create an rpart model, I only get one root node where I know I should get at least 6 based on other tools. I have checked the forums and most of the instances where this happens is where there are 50 records which makes sense (low volumes). However, this is not the case for my dataset. There are no missing values and the predictors are well distributed. My code is: fit - rpart(Responded ~ ., method=class, data=ed) Am I missing something obvious? Thanks very much... Rob [[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] format.pval () and printCoefmat ()
Hi Pradip, It this is just formatting issue, it is possible to do that with ?formatC() or ?sprintf(), but it may change those variables from numeric to character. One possibilty from `res`: res-data.frame(dat1[,1:2],read.table(text=Lines2,header=TRUE)) varsNum-sapply(res,is.numeric) res[varsNum]-lapply(res[varsNum],round,digits=3) #Here, the numeric columns with digits3 are not changed, but the ones with 3 were all changed to digits3. As I mentioned, sprintf() changes the number of digits as.data.frame(do.call(cbind,lapply(res[varsNum],function(x) sprintf(%.3f,x # mean_level1 mean_level2 rel_diff p_mean cohens_d #1 18.700 11.910 0.574 0.000 0.175 #2 18.700 14.460 0.297 0.000 0.110 #3 18.700 13.540 0.384 0.000 0.134 A.K. - Original Message - From: Muhuri, Pradip (SAMHSA/CBHSQ) pradip.muh...@samhsa.hhs.gov To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; David Winsemius dwinsem...@comcast.net Sent: Saturday, December 15, 2012 10:12 AM Subject: RE: [R] format.pval () and printCoefmat () Dear Arun and David, I am so grateful to you for all your help with the code. Thanks and regards, Pradip Arun - All this is very helpful. In general, I can follow the code. I only have the following questions: What changes in the code would be required to have 3 places after decimal for all numeric variables in the res data frame? Thanks, Pradip ### below is the display of the data from Lines1, Lines2, and res head (data.frame(Lines1)) Lines1 1 mean_level1 mean_level2 rel_diff p_mean cohens_d 2 1 18.744 11.911 0.574 0.00 0.175 3 2 18.744 14.455 0.297 0.00 0.110 4 3 18.744 13.540 0.384 0.00 0.133 5 4 18.744 6.002 2.123 0.00 0.333 6 5 18.744 5.834 2.213 0.00 0.349 head (data.frame(Lines2)) Lines2 1 mean_level1 mean_level2 rel_diff p_mean cohens_d 2 1 18.744 11.911 0.574 0.00 0.175 3 2 18.744 14.455 0.297 0.00 0.110 4 3 18.744 13.540 0.384 0.00 0.133 5 4 18.744 6.002 2.123 0.00 0.333 6 5 18.744 5.834 2.213 0.00 0.349 head (res) contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diff p_mean cohens_d 1 wh 2+hi 18.7 11.91 0.574 0 0.175 2 wh 2+rc 18.7 14.46 0.297 0 0.110 3 wh aian 18.7 13.54 0.384 0 0.133 4 wh asan 18.7 6.00 2.123 0 0.333 5 wh blck 18.7 5.83 2.213 0 0.349 6 wh csam 18.7 7.93 1.363 0 0.279 From: arun [smartpink...@yahoo.com] Sent: Friday, December 14, 2012 10:12 PM To: Muhuri, Pradip (SAMHSA/CBHSQ) Cc: R help; David Winsemius Subject: Re: [R] format.pval () and printCoefmat () Hi Pradip, May be this helps: dat1-read.table(text= contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diff p_mean cohens_d 1 wh 2+hi 18.7 11.91 0.574 1.64e-05 0.1753 2 wh 2+rc 18.7 14.46 0.297 9.24e-06 0.1101 3 wh aian 18.7 13.54 0.384 9.01e-05 0.1335 4 wh asan 18.7 6.00 2.123 2.20e-119 0.3326 5 wh blck 18.7 5.83 2.213 0.00e+00 0.3490 6 wh csam 18.7 7.93 1.363 1.27e-47 0.2793 7 wh cub 18.7 10.85 0.728 6.12e-08 0.2025 8 wh dmcn 18.7 7.13 1.629 1.59e-15 0.2981 9 wh hisp 18.7 9.72 0.928 3.27e-125 0.2420 10 wh mex 18.7 9.60 0.952 8.81e-103 0.2420 11 wh nhpi 18.7 16.14 0.162 1.74e-01 0.0669 12 wh othh 18.7 NA NA NA NA 13 wh pr 18.7 10.47 0.791 3.64e-23 0.2131 14 wh spn 18.7 15.15 0.237 1.58e-02 0.0922 ,sep=,header=TRUE,stringsAsFactors=FALSE) Lines1-capture.output(printCoefmat(dat1[,-c(1:2)],has.Pvalue=TRUE,eps.Pvalue=0.001)) Lines2-gsub(\\s+$,,gsub(\\.$,,Lines1[1:15])) res-data.frame(dat1[,1:2],read.table(text=Lines2,header=TRUE)) #or # res-cbind(dat1[,1:2],read.table(text=Lines2,header=TRUE)) res # contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diff p_mean #1 wh 2+hi 18.7 11.91 0.574 0. #2
[R] The R Journal, Volume 4, Issue 2
Dear All, The latest issue of The R Journal is now available at http://journal.r-project.org/current.html Thanks to everyone involved. Martyn Plummer Editor-in-Chief --- This message and its attachments are strictly confidenti...{{dropped:8}} ___ r-annou...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-announce __ 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] xlim/ylim problem
Hi everybody, just arrived at R and immediately I got a problem. Here's my script: setwd(C:/Users/Tom/Eigene Tools/Programming/R/Data) blast_hits-read.table(blastHit_covLenght.txt, header=T) blast_hits - as.matrix(blast_hits) numerical1-data.matrix(blast_hits, rownames.force = NA) table_no_blast_hits-read.table(noBlastHits.txt, header=T) no_blast_hits - as.matrix(table_no_blast_hits) numerical2-data.matrix(no_blast_hits, rownames.force = NA) All-merge(numerical1, numerical2, all=TRUE) library(hexbin) bin-hexbin(All, xbins=100) # The next line works pretty good, but there is one extrem artefact in the data, which let collaps all the data to a small area # plot(bin, main=All,colramp=function(n){heat.ob(n,beg=230,end=25)}) # So I tried to scale my yaxes, with the next line: #plot(bin, main=All,ylim=(0,15000), colramp=function(n){heat.ob(n,beg=230,end=25)}) # The following error message is displayed: #Fehler: Unerwartete(s) ',' in plot(bin, main=All,ylim=(0, # Which I would translate to: # Error: Unexpected ',' in plot(bin, main=All,ylim=(0, I flashing idea would be a great help Thx Tom [[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] troubles reading a text file
Dear R experts, For quite some time I have been trying to solve a mistery of reading a seemingly trouble-free text file. The data is temperature reconstruction arranged as a huge grid, preceded by seven header lines (which you see better if file is opened in Firefox or Chrome). This is the data (gridded temperature reconstruction) ftp://ftp.ncdc.noaa.gov/pub/data/paleo/historical/europe/casty2007/temp-mon.txt And this is original data description: ftp://ftp.ncdc.noaa.gov/pub/data/paleo/historical/europe/casty2007/readme-casty2007.txt Basically, it is says space-delimited ASCII format there ... I tried this: Temperature-read.table(FileName,skip = 7, header = TRUE, na.strings=NA,sep=) But .. Temperature - read.table(FileName, skip = 7, header = FALSE, sep=) Error in read.table(FileName, skip = 7, header = FALSE, sep = ) : empty beginning of file Trying read.csv gives this: Error: cannot allocate vector of size 370.5 Mb I attempted to handle this by opening and resaving the file in another software, but even if I can still see the first lines of the file in the import dialog, the full reading of the file always ends up with an error, possibly because of the huge humber of columns .. I believe the problem is with some special encoding but I cannot figure out how to go around it. Could some of you give me any hint on that? many thanks in advance Igor Igor Drobyshev Dendrochronological laboratory at Station de Recheche FERLD, director Chaire industrielle CRSNG-UQAT-UQAM en aménagement forestier durable Université du Québec en Abitibi-Témiscamingue 445 boul . de l'Université Rouyn-Noranda, QC Canada J9X5E4 http://www.dendro.uqat.ca/ [[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] xlim/ylim problem
try ylim=c(0,1500) You are missing the c which constructs a vector, without the c it gets confused. On Sat, Dec 15, 2012 at 5:14 PM, Tom Hoffrichter tom.hoffrich...@googlemail.com wrote: Hi everybody, just arrived at R and immediately I got a problem. Here's my script: setwd(C:/Users/Tom/Eigene Tools/Programming/R/Data) blast_hits-read.table(blastHit_covLenght.txt, header=T) blast_hits - as.matrix(blast_hits) numerical1-data.matrix(blast_hits, rownames.force = NA) table_no_blast_hits-read.table(noBlastHits.txt, header=T) no_blast_hits - as.matrix(table_no_blast_hits) numerical2-data.matrix(no_blast_hits, rownames.force = NA) All-merge(numerical1, numerical2, all=TRUE) library(hexbin) bin-hexbin(All, xbins=100) # The next line works pretty good, but there is one extrem artefact in the data, which let collaps all the data to a small area # plot(bin, main=All,colramp=function(n){heat.ob(n,beg=230,end=25)}) # So I tried to scale my yaxes, with the next line: #plot(bin, main=All,ylim=(0,15000), colramp=function(n){heat.ob(n,beg=230,end=25)}) # The following error message is displayed: #Fehler: Unerwartete(s) ',' in plot(bin, main=All,ylim=(0, # Which I would translate to: # Error: Unexpected ',' in plot(bin, main=All,ylim=(0, I flashing idea would be a great help Thx Tom [[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. -- Gregory (Greg) L. Snow Ph.D. 538...@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.
Re: [R] xlim/ylim problem
Hi, ylim=c(0,15000) HTH Pascal Le 12/12/16 9:14, Tom Hoffrichter a écrit : Hi everybody, just arrived at R and immediately I got a problem. Here's my script: setwd(C:/Users/Tom/Eigene Tools/Programming/R/Data) blast_hits-read.table(blastHit_covLenght.txt, header=T) blast_hits - as.matrix(blast_hits) numerical1-data.matrix(blast_hits, rownames.force = NA) table_no_blast_hits-read.table(noBlastHits.txt, header=T) no_blast_hits - as.matrix(table_no_blast_hits) numerical2-data.matrix(no_blast_hits, rownames.force = NA) All-merge(numerical1, numerical2, all=TRUE) library(hexbin) bin-hexbin(All, xbins=100) # The next line works pretty good, but there is one extrem artefact in the data, which let collaps all the data to a small area # plot(bin, main=All,colramp=function(n){heat.ob(n,beg=230,end=25)}) # So I tried to scale my yaxes, with the next line: #plot(bin, main=All,ylim=(0,15000), colramp=function(n){heat.ob(n,beg=230,end=25)}) # The following error message is displayed: #Fehler: Unerwartete(s) ',' in plot(bin, main=All,ylim=(0, # Which I would translate to: # Error: Unexpected ',' in plot(bin, main=All,ylim=(0, I flashing idea would be a great help Thx Tom [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to handle NA values in aggregate()
Dear All: I am trying to calculate four columns' means in a dataframe like this: FID MID IID EW_INCU EW_17.5 EMWEEratio 1 4621 TWF2H545.26NA 15.61 NA 1 4621 TWF2H648.0244.09 13.41 0.3041506 2 4630 TWF2H19 51.44 47.81 NA NA 2 4631 TWF2H21 NA 52.72 16.70 0.3167678 2 4632 TWF2H22 55.70 50.45 16.48 0.3266601 2 4633 TWF2H23 44.42 40.89 12.96 0.3169479 I try this code aggregate(df[,4:7],df[,1],mean) But I couldn't set the agrument na.rm=T in the mean() function,so the results are all NAs Please tell me how to handle NA values in the use of aggregate() Thanks a lot Yao He — Master candidate in 2rd year Department of Animal genetics breeding Room 436,College of Animial ScienceTechnology, China Agriculture University,Beijing,100193 E-mail: yao.h.1...@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] How to make a prior graph
Hello, could you tell me which is the command for create graphics of this prior distributions: Uniform (flat prior) Jeffrey's Thanks, Tania Sent from my iPod __ 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] average X value of specific Y
Hello I have a table describing butterfly range traits. It is composed of three columns as below Species name range size (X)latitude of range midpoint (Y) There are 11 kinds of butterflies. Each has its range size, and the latitude of each range midpoint ranges from 9 to 19. I would like to have the average range size of every degree of latitude. For example, the average range size of latitude degree 10 (10.0-10.99: Butterfly A2, B1, B2) Please kindly help with python code to calculate the average values. Thank you. Elaine The details are as followed. Butterfly A1 130.5 9.45 Butterfly A2 450.68 10.2 Butterfly A3 1102.389.3 Butterfly A4893.34 16.4 Butterfly B1 820.2 10.54 Butterfly B2872.2 10.87 Butterfly B3488.2 16.79 Butterfly B4620.11 18.3 Butterfly B5982.78 12.98 Butterfly C1 720.32 12.67 Butterfly C2912.2 18.07 [[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] averaging X of specific Y (latitude)
Hello I have a table describing butterfly range traits. It is composed of three columns as below Species name range size (X)latitude of range midpoint (Y) There are 11 kinds of butterflies. Each has its range size, and the latitude of each range midpoint ranges from 9 to 19. I would like to have the average range size of every degree of latitude. For example, the average range size of latitude degree 10 (10.0-10.99: Butterfly A2, B1, B2) Please kindly help with R code to calculate the average values. Thank you. Elaine The details are as followed. Butterfly A1 130.5 9.45 Butterfly A2 450.68 10.2 Butterfly A3 1102.389.3 Butterfly A4893.34 16.4 Butterfly B1 820.2 10.54 Butterfly B2872.2 10.87 Butterfly B3488.2 16.79 Butterfly B4620.11 18.3 Butterfly B5982.78 12.98 Butterfly C1 720.32 12.67 Butterfly C2912.2 18.07 [[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] [R-sig-Geo] averaging X of specific Y (latitude)
Hello, Yes, it is a data frame. This is the first time to hear table function or cut function. Please kindly point out how to use them. By the way, if the dataset (data frame) includes more than 2000 kinds of butterfly range sizes and the latitude of range midpoints, please kindly help with any suggestion to perform the task. Thank you Elaine On Sun, Dec 16, 2012 at 12:20 PM, Hodgess, Erin hodge...@uhd.edu wrote: Hi! Is it a data frame, please? Have you tried the table function or cut function? Sincerely, Erin From: r-sig-geo-boun...@r-project.org [r-sig-geo-boun...@r-project.org] on behalf of Elaine Kuo [elaine.kuo...@gmail.com] Sent: Saturday, December 15, 2012 10:15 PM To: r-help@r-project.org; r-sig-geo Subject: [R-sig-Geo] averaging X of specific Y (latitude) Hello I have a table describing butterfly range traits. It is composed of three columns as below Species name range size (X)latitude of range midpoint (Y) There are 11 kinds of butterflies. Each has its range size, and the latitude of each range midpoint ranges from 9 to 19. I would like to have the average range size of every degree of latitude. For example, the average range size of latitude degree 10 (10.0-10.99: Butterfly A2, B1, B2) Please kindly help with R code to calculate the average values. Thank you. Elaine The details are as followed. Butterfly A1 130.5 9.45 Butterfly A2 450.68 10.2 Butterfly A3 1102.389.3 Butterfly A4893.34 16.4 Butterfly B1 820.2 10.54 Butterfly B2872.2 10.87 Butterfly B3488.2 16.79 Butterfly B4620.11 18.3 Butterfly B5982.78 12.98 Butterfly C1 720.32 12.67 Butterfly C2912.2 18.07 [[alternative HTML version deleted]] ___ R-sig-Geo mailing list r-sig-...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo [[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] troubles reading a text file
Hi Igor, It appears that the encoding is UTF-16. readLines(temp-mon.txt) [1] þÿ [14] A search for þÿ leads to the Wikipedia page http://en.wikipedia.org/wiki/Byte_order_mark, specifically UTF-16 section. options(encoding=UTF-16) system.time(Temperature-read.table(temp-mon.txt,skip = 7, header = TRUE, na.strings=NA,sep=)) user system elapsed 28.556 0.112 28.712 ncol(Temperature) [1] 18001 Temperature[, 1:10] MM X79.75N.49.75W X79.75N.49.25W X79.75N.48.75W X79.75N.48.25W X79.75N.47.75W X79.75N.47.25W 1 176512 -32.61 -32.92 -33.34 -33.65 -34.09 -34.21 2 176601 -31.89 -31.96 -32.26 -32.48 -32.71 -33.03 X79.75N.46.75W X79.75N.46.25W X79.75N.45.75W 1 -34.65 -34.98 -35.43 2 -33.29 -33.41 -33.76 Here you can see that I have downloaded just the first 1 MB of the file, so it only has two lines after the header, but 28 seconds to read it... I'm not sure how long it would take to read.table on the whole ~600 MB file. scan() might be faster: (and this does not require setting options(encoding=UTF-16)) system.time(Temperature - scan(temp-mon.txt, fileEncoding=UTF-16, skip=8)) Read 36002 items user system elapsed 0.104 0.000 0.104 Temperature - matrix(Temperature, ncol=18001, byrow=TRUE) Temperature.colnames - scan(temp-mon.txt, character(), fileEncoding=UTF-16, skip=7, nmax=18001) Read 18001 items colnames(Temperature) - Temperature.colnames Temperature[, 1:10] MM 79.75N/49.75W 79.75N/49.25W 79.75N/48.75W 79.75N/48.25W 79.75N/47.75W 79.75N/47.25W [1,] 176512-32.61-32.92-33.34-33.65 -34.09-34.21 [2,] 176601-31.89-31.96-32.26-32.48 -32.71-33.03 79.75N/46.75W 79.75N/46.25W 79.75N/45.75W [1,]-34.65-34.98-35.43 [2,]-33.29-33.41-33.76 (note the different colnames, similar to using check.names=FALSE in read.table, and the result is a matrix, not a data frame as returned by read.table) HTH, Jeff On Sun, Dec 16, 2012 at 6:23 AM, igor.drobysh...@uqat.ca wrote: Dear R experts, For quite some time I have been trying to solve a mistery of reading a seemingly trouble-free text file. The data is temperature reconstruction arranged as a huge grid, preceded by seven header lines (which you see better if file is opened in Firefox or Chrome). This is the data (gridded temperature reconstruction) ftp://ftp.ncdc.noaa.gov/pub/data/paleo/historical/europe/casty2007/temp-mon.txt And this is original data description: ftp://ftp.ncdc.noaa.gov/pub/data/paleo/historical/europe/casty2007/readme-casty2007.txt Basically, it is says space-delimited ASCII format there ... I tried this: Temperature-read.table(FileName,skip = 7, header = TRUE, na.strings=NA,sep=) But .. Temperature - read.table(FileName, skip = 7, header = FALSE, sep=) Error in read.table(FileName, skip = 7, header = FALSE, sep = ) : empty beginning of file Trying read.csv gives this: Error: cannot allocate vector of size 370.5 Mb I attempted to handle this by opening and resaving the file in another software, but even if I can still see the first lines of the file in the import dialog, the full reading of the file always ends up with an error, possibly because of the huge humber of columns .. I believe the problem is with some special encoding but I cannot figure out how to go around it. Could some of you give me any hint on that? many thanks in advance Igor Igor Drobyshev Dendrochronological laboratory at Station de Recheche FERLD, director Chaire industrielle CRSNG-UQAT-UQAM en aménagement forestier durable Université du Québec en Abitibi-Témiscamingue 445 boul . de l'Université Rouyn-Noranda, QC Canada J9X5E4 http://www.dendro.uqat.ca/ [[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] troubles reading a text file
On Dec 15, 2012, at 2:23 PM, igor.drobysh...@uqat.ca wrote: Dear R experts, For quite some time I have been trying to solve a mistery of reading a seemingly trouble-free text file. The data is temperature reconstruction arranged as a huge grid, preceded by seven header lines (which you see better if file is opened in Firefox or Chrome). This is the data (gridded temperature reconstruction) ftp://ftp.ncdc.noaa.gov/pub/data/paleo/historical/europe/casty2007/temp-mon.txt And this is original data description: ftp://ftp.ncdc.noaa.gov/pub/data/paleo/historical/europe/casty2007/readme-casty2007.txt Basically, it is says space-delimited ASCII format there ... I tried this: Temperature-read.table(FileName,skip = 7, header = TRUE, na.strings=NA,sep=) But .. Temperature - read.table(FileName, skip = 7, header = FALSE, sep=) Error in read.table(FileName, skip = 7, header = FALSE, sep = ) : empty beginning of file After inspecting a small (8 MB fragment downloaded with an ftp client) with both Firefox and TextEdit.app and seeing that they reported this to be UTF-16 encoded, I saved it from TextEdit as UTF-8 and then could view it with R readLines. These are the first 7 lines and the beginning of the eighth: readLines(~/Downloads/temp-mon2.txt, n=10) [1] NAME \Monthly European Temperatures 1766-2000 [T=2m, Celsius]\ ! ! !
Re: [R] [R-sig-Geo] averaging X of specific Y (latitude)
Hi! Is it a data frame, please? Have you tried the table function or cut function? Sincerely, Erin From: r-sig-geo-boun...@r-project.org [r-sig-geo-boun...@r-project.org] on behalf of Elaine Kuo [elaine.kuo...@gmail.com] Sent: Saturday, December 15, 2012 10:15 PM To: r-help@r-project.org; r-sig-geo Subject: [R-sig-Geo] averaging X of specific Y (latitude) Hello I have a table describing butterfly range traits. It is composed of three columns as below Species name range size (X)latitude of range midpoint (Y) There are 11 kinds of butterflies. Each has its range size, and the latitude of each range midpoint ranges from 9 to 19. I would like to have the average range size of every degree of latitude. For example, the average range size of latitude degree 10 (10.0-10.99: Butterfly A2, B1, B2) Please kindly help with R code to calculate the average values. Thank you. Elaine The details are as followed. Butterfly A1 130.5 9.45 Butterfly A2 450.68 10.2 Butterfly A3 1102.389.3 Butterfly A4893.34 16.4 Butterfly B1 820.2 10.54 Butterfly B2872.2 10.87 Butterfly B3488.2 16.79 Butterfly B4620.11 18.3 Butterfly B5982.78 12.98 Butterfly C1 720.32 12.67 Butterfly C2912.2 18.07 [[alternative HTML version deleted]] ___ R-sig-Geo mailing list r-sig-...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo __ 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] troubles reading a text file
On Dec 15, 2012, at 8:45 PM, David Winsemius wrote: Trying read.csv gives this: Error: cannot allocate vector of size 370.5 Mb That on the other hand suggests you have inadequate machine resources for this job. Perhaps you should be thinking of using other tools than R for this project ... or buying more ram. You should probably have 32 GB for a job this size. I was wrong about that. The object size in a 64 bit R was: inp 291382512 nrow(inp) [1] 2820 length(inp) [1] 18001 (2000 - 1765)*12 [1] 2820 So it seems to be all there. It's considerably smaller than I guessed. -- David Winsemius Alameda, CA, USA __ 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] Picking out certain elements in an matrix
Suppose I have a matrix of data A 1 2 3 4 5 6 7 8 9 And I have a vector of indexes 2,1,3 For row 1 of matrix A I want the 2nd element 2 For row 2 of matrix A I want the 1st element 4 For row 3 of matrix A I want the 3rd element 9. Is there a quick way to do it ? Tjun Kiat [[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] Picking out certain elements in an matrix
On Dec 15, 2012, at 9:38 PM, Tjun Kiat Teo wrote: Suppose I have a matrix of data A 1 2 3 4 5 6 7 8 9 And I have a vector of indexes 2,1,3 For row 1 of matrix A I want the 2nd element 2 For row 2 of matrix A I want the 1st element 4 For row 3 of matrix A I want the 3rd element 9. A[ cbind( 1:3, c(2,1,3) ) ] -- David Winsemius Alameda, CA, USA __ 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 handle NA values in aggregate()
check the help file. ?aggregate says that it ignores missing values by default ;) df - read.table( header = TRUE , text = FID MID IID EW_INCU EW_17.5 EMWEEratio 1 4621 TWF2H545.26NA 15.61 NA 1 4621 TWF2H648.0244.09 13.41 0.3041506 2 4630 TWF2H19 51.44 47.81 NA NA 2 4631 TWF2H21 NA 52.72 16.70 0.3167678 2 4632 TWF2H22 55.70 50.45 16.48 0.3266601 2 4633 TWF2H23 44.42 40.89 12.96 0.3169479 ) aggregate( . ~ FID , data = df , mean ) # na.rm would need to be passed to tapply, which is a similar function tapply( df[ , 4 ] , df[ , 1 ] , mean ) tapply( df[ , 4 ] , df[ , 1 ] , mean , na.rm = TRUE ) [[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] Picking out certain elements in an matrix
On 16/12/12 18:38, Tjun Kiat Teo wrote: Suppose I have a matrix of data A 1 2 3 4 5 6 7 8 9 And I have a vector of indexes 2,1,3 For row 1 of matrix A I want the 2nd element 2 For row 2 of matrix A I want the 1st element 4 For row 3 of matrix A I want the 3rd element 9. Is there a quick way to do it ? A[cbind(1:3,c(2,1,3))] cheers, Rolf 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] how to handle NA values in aggregate()
HI, This should also work: df1-read.table(text= FID MID IID EW_INCU EW_17.5 EMW EEratio 1 4621 TWF2H5 45.26 NA 15.61 NA 1 4621 TWF2H6 48.02 44.09 13.41 0.3041506 2 4630 TWF2H19 51.44 47.81 NA NA 2 4631 TWF2H21 NA 52.72 16.70 0.3167678 2 4632 TWF2H22 55.70 50.45 16.48 0.3266601 2 4633 TWF2H23 44.42 40.89 12.96 0.3169479 ,sep=,header=TRUE,stringsAsFactors=FALSE) aggregate(df1[,4:7],by=list(df1[,1]), mean,na.rm=T) # Group.1 EW_INCU EW_17.5 EMW EEratio #1 1 46.6 44.1 14.5 0.304 #2 2 50.5 48.0 15.4 0.320 #or library(plyr) ddply(df1,.(FID),colwise(mean,c(EW_INCU,EW_17.5,EMW,EEratio)),na.rm=TRUE) # FID EW_INCU EW_17.5 EMW EEratio #1 1 46.6 44.1 14.5 0.304 #2 2 50.5 48.0 15.4 0.320 #or library(data.table) df2-data.table(df1) df3-df2[,c(1,4:7),with=FALSE] df3[,lapply(.SD,mean,na.rm=TRUE),by=FID] # FID EW_INCU EW_17.5 EMW EEratio #1: 2 50.5 48.0 15.4 0.320 #2: 1 46.6 44.1 14.5 0.304 A.K. - Original Message - From: Yao He yao.h.1...@gmail.com To: r-help@r-project.org Cc: Sent: Saturday, December 15, 2012 10:44 PM Subject: [R] how to handle NA values in aggregate() Dear All: I am trying to calculate four columns' means in a dataframe like this: FID MID IID EW_INCU EW_17.5 EMW EEratio 1 4621 TWF2H5 45.26 NA 15.61 NA 1 4621 TWF2H6 48.02 44.09 13.41 0.3041506 2 4630 TWF2H19 51.44 47.81 NA NA 2 4631 TWF2H21 NA 52.72 16.70 0.3167678 2 4632 TWF2H22 55.70 50.45 16.48 0.3266601 2 4633 TWF2H23 44.42 40.89 12.96 0.3169479 I try this code aggregate(df[,4:7],df[,1],mean) But I couldn't set the agrument na.rm=T in the mean() function,so the results are all NAs Please tell me how to handle NA values in the use of aggregate() Thanks a lot Yao He — Master candidate in 2rd year Department of Animal genetics breeding Room 436,College of Animial ScienceTechnology, China Agriculture University,Beijing,100193 E-mail: yao.h.1...@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] how to handle NA values in aggregate()
HI, Try this: df1-read.table(text= FID MID IID EW_INCU EW_17.5 EMW EEratio 1 4621 TWF2H5 45.26 NA 15.61 NA 1 4621 TWF2H6 48.02 44.09 13.41 0.3041506 2 4630 TWF2H19 51.44 47.81 NA NA 2 4631 TWF2H21 NA 52.72 16.70 0.3167678 2 4632 TWF2H22 55.70 50.45 16.48 0.3266601 2 4633 TWF2H23 44.42 40.89 12.96 0.3169479 ,sep=,header=TRUE,stringsAsFactors=FALSE) aggregate(df1[,4:7],by=list(df1[,1]),function(x) mean(x,na.rm=T)) # Group.1 EW_INCU EW_17.5 EMW EEratio #1 1 46.6 44.1 14.5 0.304 #2 2 50.5 48.0 15.4 0.320 - Original Message - From: Yao He yao.h.1...@gmail.com To: r-help@r-project.org Cc: Sent: Saturday, December 15, 2012 10:44 PM Subject: [R] how to handle NA values in aggregate() Dear All: I am trying to calculate four columns' means in a dataframe like this: FID MID IID EW_INCU EW_17.5 EMW EEratio 1 4621 TWF2H5 45.26 NA 15.61 NA 1 4621 TWF2H6 48.02 44.09 13.41 0.3041506 2 4630 TWF2H19 51.44 47.81 NA NA 2 4631 TWF2H21 NA 52.72 16.70 0.3167678 2 4632 TWF2H22 55.70 50.45 16.48 0.3266601 2 4633 TWF2H23 44.42 40.89 12.96 0.3169479 I try this code aggregate(df[,4:7],df[,1],mean) But I couldn't set the agrument na.rm=T in the mean() function,so the results are all NAs Please tell me how to handle NA values in the use of aggregate() Thanks a lot Yao He — Master candidate in 2rd year Department of Animal genetics breeding Room 436,College of Animial ScienceTechnology, China Agriculture University,Beijing,100193 E-mail: yao.h.1...@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.