[R] How to fine control bar plot width?
Dear expert, I want to combine 4 figures in the same plot. Each bar plot is related to the image() plot. I want to bar width is extractly the same width as grid width in the image() plot. The up-barplot and the left-barplot. I have pasted my code to follow. How can I modify for this purpose? Thank you very much in advance. ###My example code### datMat - matrix(rep(1,100),nrow=10) op=par(oma=c(1,1,1,1),mar=c(1,1,1,1),lwd = 0.2,cex=.5) nf - layout(matrix(c(0,1,0,2,3,4),2,3,byrow=TRUE), widths=c(1,6,1), heights=c(1,3), respect=TRUE) par(mar=c(3,0.5,3,0),mgp=c(0,1,-2.2)) barplot(seq(1,10),width=1,xlim=c(0,ncol(datMat)),xlab=, space=0,col=blue,border = white ) box(inner, lty=dotted, col=green) box(outer, lty=solid, col=green) par(mar=c(0,0,0,0),mgp=c(0,1,-1)) barplot(-seq(1,10),ylim=c(0,nrow(datMat)),width=1.025,horiz=TRUE,,axes = T,space=0,col=blue, border = white ) par(mar=c(1,0,0,0)) x.len=ncol(datMat) y.len=nrow(datMat) single.col= 'chartreuse4' double.col= 'blue4' triple.col= '#33' four.col= '#FF7F00' five.col= '#E41A1C' colors=c('grey90',single.col, double.col,triple.col,four.col,five.col); image(x=1:x.len, y=1:y.len, z=t(datMat), col = colors, breaks=c(-0.5 ,0.5 ,1.5 ,2.5 ,3.5 ,4.5 ,5.5), axes = FALSE, ann=F); abline(h=seq(0.5,0.5+y.len),col='white',lwd=0.5); abline(v=seq(0.5,0.5+x.len),col='white',lwd=0.5) par(mar=c(0,0,0,0),mgp=c(0,1,0)) barplot(seq(1,10),ylim=c(0,nrow(datMat)),width=.5,horiz=TRUE,axes = FALSE, space=0,col=blue,border =white ) axis(side=1) ## sessionInfo() R version 3.1.1 (2014-07-10) Platform: x86_64-apple-darwin13.1.0 (64-bit) locale: [1] C/UTF-8/C/C/C/C attached base packages: [1] datasets utils stats graphics grDevices methods base other attached packages: [1] xlsx_0.5.7 xlsxjars_0.6.1 [3] rJava_0.9-6 nutshell_2.0 [5] nutshell.audioscrobbler_1.0 nutshell.bbdb_1.0 [7] faraway_1.0.6 MASS_7.3-35 loaded via a namespace (and not attached): [1] tools_3.1.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, reproducible code.
[R] How can make loop more faster?
Dear expert, How can I make follow codematrix function more faster? top20.dat - top20.dat[,7:length(top20.dat[1,])] top40.dat - read.table(top40snps.ped,header=F,sep=\t,stringsAsFactors=F) row.names(top40.dat) - top40.dat[,1] top40.dat - top40.dat[,7:length(top40.dat[1,])] codematrix - function(dat) { new.dat - dat for(col in 1:length(dat[1,])) { tbl - table(dat[,col]) max.allel - names(which(tbl==max(table(dat[,col] for(row in 1:length(dat[,1])) { if(dat[row,col]==0 0) { new.dat[row,col]=NA }else{ if(dat[row,col]==max.allel) { new.dat[row,col]=0 }else{ allele - unlist(strsplit( as.character(dat[row,col]), )) if(allele[1]==allele[2]){ new.dat[row,col]=2 }else{ new.dat[row,col]=1 } } } } #}) cat(paste(col, ,sep=)) } return(new.dat) } code.top20 - codematrix(top20.dat) [[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] Add text A, B, C and D on multiple ordered plot
Dear list, Is there a elegant way to name multiple ordered plot as A, B, C and D? Just put A, B, C and D on the top left corner of each plot. Usually I do it in Illustrator, but I think in R should there is a way. Could you please provide a example? Thank you very much in advance. __ 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] Add text A, B, C and D on multiple ordered plot
Thank your reminder. Here is the example code: a- rnorm(1000,0,1) b-rnorm(1000,0,2) c-rnorm(1000,0,3) d-rnorm(1000,0,4) par(mfrow=c(2,2)) hist(a) hist(b) hist(c) hist(d) I want to add A, B, C and D on each top left. On Fri, Feb 8, 2013 at 2:35 PM, John Kane jrkrid...@inbox.com wrote: Yes there probably is if you would show us what you are doing. Minimal working code helps. https://github.com/hadley/devtools/wiki/Reproducibility John Kane Kingston ON Canada -Original Message- From: fabrice.c...@gmail.com Sent: Fri, 8 Feb 2013 14:28:17 -0500 To: r-help@r-project.org Subject: [R] Add text A, B, C and D on multiple ordered plot Dear list, Is there a elegant way to name multiple ordered plot as A, B, C and D? Just put A, B, C and D on the top left corner of each plot. Usually I do it in Illustrator, but I think in R should there is a way. Could you please provide a example? Thank you very much in advance. __ 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. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ 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] Add text A, B, C and D on multiple ordered plot
John Kane, Thanks. It makes some of sense. But it seems not exactly what I want. I just remember it need using mtext and adjust margin. I saw such of example long time ago, but I have forgotten it. On Fri, Feb 8, 2013 at 3:32 PM, John Kane jrkrid...@inbox.com wrote: Here is a rough example of what you want. You will need to adjust the actual placement by hand by redefining the x y values. set.seed(100) a - rnorm(1000,0,1) b -rnorm(1000,0,2) c -rnorm(1000,0,3) d -rnorm(1000,0,4) opr - par(mfrow=c(2,2)) hist(a) text(-3, 150, labels =a) hist(b) text(-4, 150, labels =b) hist(c) text(-4, 150, labels =c) hist(d) text(-4, 150, labels =d) par - opr John Kane Kingston ON Canada -Original Message- From: fabrice.c...@gmail.com Sent: Fri, 8 Feb 2013 14:42:10 -0500 To: jrkrid...@inbox.com Subject: Re: [R] Add text A, B, C and D on multiple ordered plot Thank your reminder. Here is the example code: a- rnorm(1000,0,1) b-rnorm(1000,0,2) c-rnorm(1000,0,3) d-rnorm(1000,0,4) par(mfrow=c(2,2)) hist(a) hist(b) hist(c) hist(d) I want to add A, B, C and D on each top left. On Fri, Feb 8, 2013 at 2:35 PM, John Kane jrkrid...@inbox.com wrote: Yes there probably is if you would show us what you are doing. Minimal working code helps. https://github.com/hadley/devtools/wiki/Reproducibility John Kane Kingston ON Canada -Original Message- From: fabrice.c...@gmail.com Sent: Fri, 8 Feb 2013 14:28:17 -0500 To: r-help@r-project.org Subject: [R] Add text A, B, C and D on multiple ordered plot Dear list, Is there a elegant way to name multiple ordered plot as A, B, C and D? Just put A, B, C and D on the top left corner of each plot. Usually I do it in Illustrator, but I think in R should there is a way. Could you please provide a example? Thank you very much in advance. __ 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. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ 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. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth __ 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] Package: VennDiagram. Error in draw.pairwise.venn Impossible: cross section area too large
Dear list, When I use VennDiagram package, I got a error as follow: venn.plot - draw.pairwise.venn( area1 = 3186, area2 = 325, cross.area = 5880); Error in draw.pairwise.venn(area1 = 3186, area2 = 325, cross.area = 588) : Impossible: cross section area too large. Does anyone have suggestion? Thank you. __ 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] Package: VennDiagram. Error in draw.pairwise.venn Impossible: cross section area too large
Thank you all. Yes. I just miss understand this part. Now it is OK. On Sun, Jan 27, 2013 at 7:41 PM, Paul Boutros paul.bout...@oicr.on.ca wrote: Hi Fabrice, The cross.area parameter gives the size of the intersection, which cannot be larger than the size of either set 1 (area1 parameter) or set 2 (area2 parameter). You probably want: venn.plot - draw.pairwise.venn( area1 = 3186 + 5880, area2 = 325 + 5880, cross.area = 5880); Paul -Original Message- From: hiek...@gmail.com [mailto:hiek...@gmail.com] On Behalf Of Fabrice Tourre Sent: January-27-13 5:06 PM To: r-help@r-project.org Cc: Paul Boutros Subject: Package: VennDiagram. Error in draw.pairwise.venn Impossible: cross section area too large Dear list, When I use VennDiagram package, I got a error as follow: venn.plot - draw.pairwise.venn( area1 = 3186, area2 = 325, cross.area = 5880); Error in draw.pairwise.venn(area1 = 3186, area2 = 325, cross.area = 588) : Impossible: cross section area too large. Does anyone have suggestion? Thank you. __ 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] Basic question about: - and method start with dot.
require(fortunes) Loading required package: fortunes fortune(-) I wish - had never been invented, as it makes an esoteric and dangerous feature of the language *seem* normal and reasonable. If you want to dumb down R/S into a macro language, this is the operator for you. -- Bill Venables R-help (July 2001) On Tue, Oct 2, 2012 at 11:14 AM, peter dalgaard pda...@gmail.com wrote: On Oct 2, 2012, at 13:35 , Hadley Wickham wrote: What is the special meaning for the method name start with a dot? It means nothing in particular, except that such objects don't show up in ls() by default. The _intention_ is usually that the function is only to be used internally and not for end-user use. But these days, if you're writing a package, you're better off using namespaces. Sure, but that doesn't keep package writers from using that kind of naming convention for non-exported objects. (Notice that this started as a question about reading 3rd party source codes.) -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@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] Basic question about: - and method start with dot.
Dear list, When I read some source code, I find lot of place used symbol - , e.g. lastTime - newTime; What is the meaning here? Also, I find some method with the name start with dot, e.g. .RowStandardizeCentered = function(x) { div = sqrt( rowSums(x^2) ); div[ div == 0 ] = 1; return( x/div ); } What is the special meaning for the method name start with a dot? Thank you very much in advance. __ 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] multicore, mclapply memory problem
Dear list, I am using mclapply(from multicore) to use multiple cores on one server. If I do not use mclapply, just one core, my R problem will use 4G memory. When I use mclapply and set mc.cores =10, each core will use 4G memory. So totally it will use 40G memory. Is it possible let each core to share some memory on the same server? Thank you. __ 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] multicore, mclapply memory problem
Thank you for your reply. I used debian system. I will try parallel. Thanks. uname -a Linux m1000e1-m610-6 2.6.26-2-amd64 #1 SMP Tue Mar 9 22:29:32 UTC 2010 x86_64 GNU/Linux sessionInfo() R version 2.14.2 (2012-02-29) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] multicore_0.1-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] Multi-threads in R
I think multicore is one of answer if you can write your function in to lapply. On Mon, Jun 18, 2012 at 12:14 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: I would argue (somewhat emphatically) that the parallel facilities you are looking at are absolutely not for `for` loops. `for` loops are a control structure native to imperative programming and, as such, are inherently stateful. This provides many advantages, but easy parallelization is absolutely not one of them. Rather consider R as a functional language and the appropriate control structure is the Map(), most famously of MapReduce, but also inherent in R's *apply() family of functions. The careful reader will note that here is where parallelization is exposed. By being state-free, there's no inherent sequentiality and, consequently, no barriers to parallel computing. For a somewhat concrete example consider what it would take to do a state-dependent simulation (like a gibbs sampler) in parallel: it is, to my mind, quite non-trivial. Compare this to the question of doing column sums of a matrix in parallel -- effectively trivial. The parallelization afforded by R is of that second sort. A red herring in this discussion is the foreach() formalism, but a moment's thought suggests to me that foreach() is much closer to Map() than to for(). Best, Michael On Sun, Jun 17, 2012 at 1:23 PM, Gary Dong pdxgary...@gmail.com wrote: Thanks for all replied. I read the introduction of R parallel. Is it for loops only? Gary On Sun, Jun 17, 2012 at 10:04 AM, R. Michael Weylandt michael.weyla...@gmail.com michael.weyla...@gmail.com wrote: Take a look at the parallel package which ships with all current versions of R. Michael On Jun 17, 2012, at 11:39 AM, Gary Dong pdxgary...@gmail.com wrote: Dear R users, I'm wonder if there is a easy way to make R use multi-CPUs on my computer. My computer has four CPUs but R uses only one. Thanks. Gary [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] wgcna
Peter, Thank you. In fact, I am also very interesting to WGCNA. On Sat, Jun 16, 2012 at 3:29 AM, Peter Langfelder peter.langfel...@gmail.com wrote: On Fri, Jun 15, 2012 at 8:04 AM, Ingezz irholt...@gmail.com wrote: Dear Peter, I am trying to apply the WGCNA meta-analysis for two (or more) microarray datasets-tutorial to my own data. mp=modulePreservation(multiExpr,multiColor,referenceNetworks=1,verbose=3,networkType=signed, nPermutations=30,maxGoldModuleSize=100,maxModuleSize=400) However, the error I am getting is: Error in .checkExpr(multiData, verbose, indent) : The submitted 'multiExpr' data contain genes or samples with zero variance or excessive counts of missing entries. Please use the function goodSamplesGenes on each set to filter out the problematic genes and samples before running modulePreservation. Seems pretty clear, but applying goodSamplesGenes function results in no exclusions for both arrays. GM2 - goodSamplesGenes(M2, minFraction = 1/2, minNSamples =8, minNGenes =20) What could be the issue here? Should I increase the stringency? What stringency should be used with goodsamplegenes for modulepreservation to work? Hi Inge, first, I suggest that in the future you contact me directly, since others on this list probably have no idea what we're talking about. It is difficult to diagnose the problem without the data. I suggest you specify the verbose argument to both functions with a high value (e.g., 5) which should produce more informative output. I assume you are aware of the fact that the function goodSamplesGenes returns a list whose component allOK determines whether any genes or samples should be removed. Other components in the list specify which genes and/or samples should be removed. The actual removal needs to be done by you (I haven't written a function to do that yet but may do so in the future to make it more convenient). In this sense the error message is a bit misleading and I will change that as well. HTH, 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. __ 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] gsub/strsplit with multiple patterns/splits
0 and 1 means zero or 1 match. Want to remove the word Energy? gsub(( Energy){0,1},{0,1} Inc[.]{0,1}, , DF) On Thu, May 31, 2012 at 11:45 AM, mdvaan mathijsdev...@gmail.com wrote: Thanks! That works like a charm, but I am not sure if I fully understand the syntax. I looked at the gsub page but still couldn't figure it out. What does the pattern part (,{0,1} Inc[.]{0,1}) do? What do the 0 and 1 within the curly brackets refer to? Also, what if, for example, I would want to remove the word Energy? Thank you very much in advance. Math -- View this message in context: http://r.789695.n4.nabble.com/gsub-strsplit-with-multiple-patterns-splits-tp4631873p4631897.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] Simple example for High performance computing with R?
Dear list, I want to run two independent calculation (A, B) and then combined their results to do a plot in R. Before I just run calculation A first, then calculation B. It will take some times. I just have one server with multiple core. I noticed that there are some nice package in R for parallel calculation, such as parallel, multicore and snow. Also there is a book, O’Reilly – “Parallel R, Data Analysis in the Distributed World” book by Q. Ethan McCallum and Stephen Weston. When track into these packages, I am a little of lost because I did not know parallel calculation too much. Could any one can give me some example codes for my purpose? So I can easy follow. Thank you very much in advance. __ 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 can I check a package is installed or not?
Dear list, How can I detect a package is installed or not? If not, then install it. For example, in a script, I want to check the package DESeq is installed or not. If not, then I will using this script to install it. source(http://www.bioconductor.org/biocLite.R;) biocLite(DESeq) The pseudo script would be like this: try: library(DESeq) catch: source(http://www.bioconductor.org/biocLite.R;) biocLite(DESeq) Thank you __ 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 can I check a package is installed or not?
Thank you for your sharing I got it. On Tue, Sep 27, 2011 at 9:44 PM, David Winsemius dwinsem...@comcast.net wrote: On Sep 27, 2011, at 3:19 PM, Fabrice Tourre wrote: Dear list, How can I detect a package is installed or not? If not, then install it. For example, in a script, I want to check the package DESeq is installed or not. If not, then I will using this script to install it. source(http://www.bioconductor.org/biocLite.R;) biocLite(DESeq) The pseudo script would be like this: try: library( Perhaps: if ( require(DESeq) ) { do-stuff } else { source(http://www.bioconductor.org/biocLite.R;) biocLite(DESeq) } 'require' reports success or failure with a logical and loads the package if successful. You need to add logical.return=TRUE to a 'library' call to get avoid getting a character value back. catch: source(http://www.bioconductor.org/biocLite.R;) biocLite(DESeq) Thank you __ 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.
[R] Calculated mean value based on another column bin from dataframe.
Dear list, I have a dataframe with two column as fellow. head(dat) V1 V2 0.15624 0.94567 0.26039 0.66442 0.16629 0.97822 0.23474 0.72079 0.11037 0.83760 0.14969 0.91312 I want to get the column V2 mean value based on the bin of column of V1. I write the code as fellow. It works, but I think this is not the elegant way. Any suggestions? dat-read.table(dat.txt,head=F) ran-seq(0,0.5,0.05) mm-NULL for (i in c(1:(length(ran)-1))) { fil- dat[,1] ran[i] dat[,1]=ran[i+1] m-mean(dat[fil,2]) mm-c(mm,m) } mm Here is the first 20 lines of my data. dput(head(dat,20)) structure(list(V1 = c(0.15624, 0.26039, 0.16629, 0.23474, 0.11037, 0.14969, 0.16166, 0.09785, 0.36417, 0.08005, 0.29597, 0.14856, 0.17307, 0.36718, 0.11621, 0.23281, 0.10415, 0.1025, 0.04238, 0.13525), V2 = c(0.94567, 0.66442, 0.97822, 0.72079, 0.8376, 0.91312, 0.88463, 0.82432, 0.55582, 0.9429, 0.78956, 0.93424, 0.87692, 0.83996, 0.74552, 0.9779, 0.9958, 0.9783, 0.92523, 0.99022 )), .Names = c(V1, V2), row.names = c(NA, 20L), class = data.frame) __ 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] Calculated mean value based on another column bin from dataframe.
Dear Henrique Dallazuanna, Thank you very much for your suggestion. It is obvious that your method is better than me. Is it possible to use cut, table,by etc? Whether there is some aggregate function in R can do this? Thanks. On Wed, Apr 6, 2011 at 2:16 PM, Henrique Dallazuanna www...@gmail.com wrote: Try this: fil - sapply(ran, '', e1 = dat[,1]) sapply(ran[2:(length(ran) + 1)], '=', e1 = dat[,1]) mm - apply(fil, 2, function(idx)mean(dat[idx, 2])) On Wed, Apr 6, 2011 at 5:48 AM, Fabrice Tourre fabrice.c...@gmail.com wrote: Dear list, I have a dataframe with two column as fellow. head(dat) V1 V2 0.15624 0.94567 0.26039 0.66442 0.16629 0.97822 0.23474 0.72079 0.11037 0.83760 0.14969 0.91312 I want to get the column V2 mean value based on the bin of column of V1. I write the code as fellow. It works, but I think this is not the elegant way. Any suggestions? dat-read.table(dat.txt,head=F) ran-seq(0,0.5,0.05) mm-NULL for (i in c(1:(length(ran)-1))) { fil- dat[,1] ran[i] dat[,1]=ran[i+1] m-mean(dat[fil,2]) mm-c(mm,m) } mm Here is the first 20 lines of my data. dput(head(dat,20)) structure(list(V1 = c(0.15624, 0.26039, 0.16629, 0.23474, 0.11037, 0.14969, 0.16166, 0.09785, 0.36417, 0.08005, 0.29597, 0.14856, 0.17307, 0.36718, 0.11621, 0.23281, 0.10415, 0.1025, 0.04238, 0.13525), V2 = c(0.94567, 0.66442, 0.97822, 0.72079, 0.8376, 0.91312, 0.88463, 0.82432, 0.55582, 0.9429, 0.78956, 0.93424, 0.87692, 0.83996, 0.74552, 0.9779, 0.9958, 0.9783, 0.92523, 0.99022 )), .Names = c(V1, V2), row.names = c(NA, 20L), class = data.frame) __ 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 __ 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] Odp: Calculated mean value based on another column bin from dataframe.
This is extractly what I want. Thank you very much. On Wed, Apr 6, 2011 at 5:22 PM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi r-help-boun...@r-project.org napsal dne 06.04.2011 10:48:04: Dear list, I have a dataframe with two column as fellow. head(dat) V1 V2 0.15624 0.94567 0.26039 0.66442 0.16629 0.97822 0.23474 0.72079 0.11037 0.83760 0.14969 0.91312 I want to get the column V2 mean value based on the bin of column of V1. I write the code as fellow. It works, but I think this is not the elegant way. Any suggestions? Do you want something like that? #make data x-runif(100) y-runif(100) #cut first column to bins (in your case dat[,1] and ran) x.c-cut(x, seq(0,1,.1)) #aggregate column 2 according to bins (in your case dat[,2]) aggregate(y,list(x.c), mean) Group.1 x 1 (0,0.1] 0.5868734 2 (0.1,0.2] 0.5436263 3 (0.2,0.3] 0.5099366 4 (0.3,0.4] 0.4815855 5 (0.4,0.5] 0.4137687 6 (0.5,0.6] 0.4698156 7 (0.6,0.7] 0.4687639 8 (0.7,0.8] 0.5661048 9 (0.8,0.9] 0.5489297 10 (0.9,1] 0.4812521 Regards Petr dat-read.table(dat.txt,head=F) ran-seq(0,0.5,0.05) mm-NULL for (i in c(1:(length(ran)-1))) { fil- dat[,1] ran[i] dat[,1]=ran[i+1] m-mean(dat[fil,2]) mm-c(mm,m) } mm Here is the first 20 lines of my data. dput(head(dat,20)) structure(list(V1 = c(0.15624, 0.26039, 0.16629, 0.23474, 0.11037, 0.14969, 0.16166, 0.09785, 0.36417, 0.08005, 0.29597, 0.14856, 0.17307, 0.36718, 0.11621, 0.23281, 0.10415, 0.1025, 0.04238, 0.13525), V2 = c(0.94567, 0.66442, 0.97822, 0.72079, 0.8376, 0.91312, 0.88463, 0.82432, 0.55582, 0.9429, 0.78956, 0.93424, 0.87692, 0.83996, 0.74552, 0.9779, 0.9958, 0.9783, 0.92523, 0.99022 )), .Names = c(V1, V2), row.names = c(NA, 20L), class = data.frame) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Calculated mean value based on another column bin from dataframe.
Thanks. Before I never used findInterval function. It seems very nice. On Wed, Apr 6, 2011 at 11:20 PM, David Winsemius dwinsem...@comcast.net wrote: On Apr 6, 2011, at 9:46 AM, Fabrice Tourre wrote: Dear Henrique Dallazuanna, Thank you very much for your suggestion. It is obvious that your method is better than me. Is it possible to use cut, table,by etc? Whether there is some aggregate function in R can do this? Thanks. On Wed, Apr 6, 2011 at 2:16 PM, Henrique Dallazuanna www...@gmail.com wrote: Try this: fil - sapply(ran, '', e1 = dat[,1]) sapply(ran[2:(length(ran) + 1)], '=', e1 = dat[,1]) mm - apply(fil, 2, function(idx)mean(dat[idx, 2])) On Wed, Apr 6, 2011 at 5:48 AM, Fabrice Tourre fabrice.c...@gmail.com wrote: Dear list, I have a dataframe with two column as fellow. head(dat) V1 V2 0.15624 0.94567 0.26039 0.66442 0.16629 0.97822 0.23474 0.72079 0.11037 0.83760 0.14969 0.91312 I want to get the column V2 mean value based on the bin of column of V1. I write the code as fellow. It works, but I think this is not the elegant way. Any suggestions? dat-read.table(dat.txt,head=F) ran-seq(0,0.5,0.05) mm-NULL for (i in c(1:(length(ran)-1))) { fil- dat[,1] ran[i] dat[,1]=ran[i+1] m-mean(dat[fil,2]) mm-c(mm,m) } mm Here is the first 20 lines of my data. dput(head(dat,20)) structure(list(V1 = c(0.15624, 0.26039, 0.16629, 0.23474, 0.11037, 0.14969, 0.16166, 0.09785, 0.36417, 0.08005, 0.29597, 0.14856, 0.17307, 0.36718, 0.11621, 0.23281, 0.10415, 0.1025, 0.04238, 0.13525), V2 = c(0.94567, 0.66442, 0.97822, 0.72079, 0.8376, 0.91312, 0.88463, 0.82432, 0.55582, 0.9429, 0.78956, 0.93424, 0.87692, 0.83996, 0.74552, 0.9779, 0.9958, 0.9783, 0.92523, 0.99022 )), .Names = c(V1, V2), row.names = c(NA, 20L), class = data.frame) __ Here is how I would have done it with findInterval and tapply which is very similar to using a `cut` and `table` approach: dat$grp - findInterval(dat$V1, seq(0,0.5,0.05) ) tapply(dat$V2, dat$grp, mean) 1 2 3 4 5 6 8 0.9252300 0.8836100 0.9135429 0.9213600 0.8493450 0.7269900 0.6978900 #--- You do not get exactly the same form of the result as with Henrique's method. His yields: mm [1] 0.9252300 0.8836100 0.9135429 0.9213600 0.8493450 0.7269900 NaN [8] 0.6978900 NaN NaN NaN The cut approach would yield this, which is more informatively labeled. (I'm wasn't completely sure the second to last word in the prior sentence was a real word, but several dictionaries seem to think so.): dat$grp2 - cut(dat$V1 , breaks=ran) tapply(dat$V2, dat$grp2, mean) (0,0.05] (0.05,0.1] (0.1,0.15] (0.15,0.2] (0.2,0.25] (0.25,0.3] 0.9252300 0.8836100 0.9135429 0.9213600 0.8493450 0.7269900 (0.3,0.35] (0.35,0.4] (0.4,0.45] (0.45,0.5] NA 0.6978900 NA NA 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. __ 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] Calculate probabilty
Hi Rex, Thanks for you explain. In fact, my question is: When I observed that there are 6 or more balls in one box, what is this probability? The ball is randomly put into the boxes. I think it is: 1-pbinom(6,142,1/491) = 2.272026e-08. When the sample size is large, how should I do this? using chisq.test? Becuase binom test is not suitable for large sample size. For example, There are 6000 balls and 500 boxes, when I observed that there are 60 or more balls in one box, what is this probability? On Fri, Feb 25, 2011 at 6:40 PM, rex.dw...@syngenta.com wrote: Rex __ 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] Calculate probabilty
Hi List, I have a question to calculate probability using R. There are 491 boxes and 142 balles. If the ball randomly put into the box. How to calculate the probability of six or more there are in one box? I have try : dbinom(6,142,1/491) 1-pbinom(6,142,1/491) But I think I have some unclear about the dbinom and pbinom. Thank you very much in advance. __ 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 for lattice. par(new=TRUE)
Hi list, I want to plot two plot in the same figure. I set par(new=TRUE). But it does not work. library(lattice) myPanel - function(x,...) { panel.histogram(x,alpha=0.4,...) ltext(0.4,1.5,paste(Mean=,0.05,digit=2)),cex=0.8) ltext(0.8,1.5,paste(s.d.=,0.06,digit=2)),cex=0.8) } histogram(sh2, type=percent,panel=myPanel,breaks=seq(0,1,by=0.01),ylim=c(0,5),col=rgb(0.1,0.1,0.8,0.5)) par(new=TRUE) Here is does not work. Warning message: In par(new = TRUE) : calling par(new=TRUE) with no plot histogram(sh2, type=percent,panel=myPanel,breaks=seq(0,1,by=0.01),ylim=c(0,5)) I want to the two hist in the same map. How can I set it in lattice? Thanks. __ 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 find more about Covariance (in R)
population is all individual. sample is a part of population. If the sample size is enough large, mean(sr*sr)-mean(sr)*mean(sr) will almost equal to cov(sr, sr). On Wed, Jan 19, 2011 at 3:59 PM, Alaios ala...@yahoo.com wrote: Dear Josh, I would like to thank you for your reply. I think that it is clear that I miss a lot of theory. I have tried in google to read and study more about covariance but I have this feeling that the term 'covariance' is used for many different things in different topics. You mentioned for example population and sample (covariance) which are two words-terms that I can not distinguish between them. Even though this is R list could you please provide me some differences to study more about covariance before trying to implement things in R. (Even in R are some things that do not understand i.e pearson, kendal and spearman method) I would like to thank you in advance for your patience. Best Regards Alex --- On Wed, 1/19/11, Joshua Wiley jwiley.ps...@gmail.com wrote: From: Joshua Wiley jwiley.ps...@gmail.com Subject: Re: [R] How to find more about Covariance (in R) To: Alaios ala...@yahoo.com Cc: r-h...@stat.math.ethz.ch Date: Wednesday, January 19, 2011, 2:36 PM Hi Alex, cov() uses the formula for a sample covariance. The denominator is N - 1 instead of N. However, the formula you used from Wikipedia is for a population covariance. To move between the two in this case: cov(sr, sr) * (4/5) # should equal E[XX] - E[x] * E[x] Cheers, Josh On Wed, Jan 19, 2011 at 6:29 AM, Alaios ala...@yahoo.com wrote: Hello everyone, I am trying to understand how covariance work. So I created a vector called sr-c(2,5,7,5,2) so according to wikipedia Cov(X,X)=E[XX]-E[x]*E[x] which in R is mean(sr*sr)-mean(sr)*mean(sr) [1] 3.76 but also cov(sr,sr) [1] 4.7 why is this difference between these two approaches? Where I am wrong? I would like to thank you in advance for your help Best Regards Alex __ 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-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 for R plot
Hi Thanks for you suggestion. I used histograme in lattice packages. If it is possible lattice can do it, it will be better. On Mon, Jan 17, 2011 at 3:28 PM, Peter Ehlers ehl...@ucalgary.ca wrote: On 2011-01-17 02:26, Fabrice Tourre wrote: Hi all, How to plot as the coordinate as in my attachment? I want to trim the coordinate and one of plot as the figure in attachment. Does any one have such example? Thanks. Maybe you're looking for something like axis.break or gap.plot in the plotrix package? Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help for R plot
Hi all, How to plot as the coordinate as in my attachment? I want to trim the coordinate and one of plot as the figure in attachment. Does any one have such example? Thanks. attachment: Screen shot 2011-01-17 at 11.22.20 AM.png__ 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 covernt this list to data.frame?
using dget to try this data. dget(probesnum)-a some data length is 3, some is 4. thanks. __ 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.