[R] circlize package: different font size for axis labels
Hi, Dr. Gu, I am trying to highlight some axis labels, for example, "72hL3" as bold, using the following command: circos.initialize(factors=female.f, xlim=c(1.8,6.2)) circos.trackPlotRegion(factors=female.f, ylim=c(-1.3,1.8),track.height=0.5,panel.fun=function(x,y){circos.axis(major.at=c(2:6),minor.ticks=0,labels=c("L3","72hL3","72hL4","8dF","16dF"),labels.cex=0.8,major.tick.percentage=0.02,h="bottom", direction="inside", labels.font=c(1,2,1,1,1,1))})Is there a way to do this using circlize package? Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] circlize package: different font size for axis labels
I was trying to ask if there is way to change the color of the axis... Thanks! On Monday, December 15, 2014 1:39 PM, "Gu, Zuguang" wrote: Hi, In current version, `labels.font` in `circos.axis` can only be a scalar ( a vector with length one). But you can first add axes with no labels and then add labels by `circos.text`: female.f = c("a", "b") circos.initialize(factors=female.f, xlim=c(1.8,6.2)) circos.trackPlotRegion(factors=female.f, ylim=c(-1.3,1.8),track.height=0.5, panel.fun=function(x,y) { circos.axis(h = "top", major.at=c(2:6),minor.ticks=0,labels= rep("", 5),labels.cex=0.8,major.tick.percentage=0.02, direction="inside") circos.text(2:6, rep(1.5, 5), c("L3","72hL3","72hL4","8dF","16dF"), font = c(1, 2, 1, 1, 1), facing = "inside", niceFacing = TRUE) }) best, Zuguang Sent: 15 December 2014 17:41 To: r-help@r-project.org; Gu, Zuguang Subject: circlize package: different font size for axis labels Hi, Dr. Gu, I am trying to highlight some axis labels, for example, "72hL3" as bold, using the following command: circos.initialize(factors=female.f, xlim=c(1.8,6.2)) circos.trackPlotRegion(factors=female.f, ylim=c(-1.3,1.8),track.height=0.5,panel.fun=function(x,y){circos.axis(major.at=c(2:6),minor.ticks=0,labels=c("L3","72hL3","72hL4","8dF","16dF"),labels.cex=0.8,major.tick.percentage=0.02,h="bottom", direction="inside", labels.font=c(1,2,1,1,1,1))}) Is there a way to do this using circlize package? Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] circlize package: different font size for axis labels
Hi, Dr. Gu, Thank you very much for the answer. This trick works. Another question, is there a way to change the color or the axis? Thanks! On Monday, December 15, 2014 1:39 PM, "Gu, Zuguang" wrote: Hi, In current version, `labels.font` in `circos.axis` can only be a scalar ( a vector with length one). But you can first add axes with no labels and then add labels by `circos.text`: female.f = c("a", "b") circos.initialize(factors=female.f, xlim=c(1.8,6.2)) circos.trackPlotRegion(factors=female.f, ylim=c(-1.3,1.8),track.height=0.5, panel.fun=function(x,y) { circos.axis(h = "top", major.at=c(2:6),minor.ticks=0,labels= rep("", 5),labels.cex=0.8,major.tick.percentage=0.02, direction="inside") circos.text(2:6, rep(1.5, 5), c("L3","72hL3","72hL4","8dF","16dF"), font = c(1, 2, 1, 1, 1), facing = "inside", niceFacing = TRUE) }) best, Zuguang Sent: 15 December 2014 17:41 To: r-help@r-project.org; Gu, Zuguang Subject: circlize package: different font size for axis labels Hi, Dr. Gu, I am trying to highlight some axis labels, for example, "72hL3" as bold, using the following command: circos.initialize(factors=female.f, xlim=c(1.8,6.2)) circos.trackPlotRegion(factors=female.f, ylim=c(-1.3,1.8),track.height=0.5,panel.fun=function(x,y){circos.axis(major.at=c(2:6),minor.ticks=0,labels=c("L3","72hL3","72hL4","8dF","16dF"),labels.cex=0.8,major.tick.percentage=0.02,h="bottom", direction="inside", labels.font=c(1,2,1,1,1,1))}) Is there a way to do this using circlize package? Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] density plot not smooth
I have a dataset with 6187 elements, ranged from 3 to 104028. When I tried to examine only small range of data, I found that the plot was not smooth (as shown below): plot(density(test$V2), xlim=c(0,1000)) Is there away to make it smoother? Thanks a lot!! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] density plot not smooth
Thank you for the email. What is the default "n"? Thanks! On Tuesday, March 17, 2015 4:06 PM, William Dunlap wrote: Increasing the value of 'n' given to density will give an estimate at more points so it will look smoother. Try n=2^18. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 17, 2015 at 12:06 PM, Fix Ace wrote: I have a dataset with 6187 elements, ranged from 3 to 104028. When I tried to examine only small range of data, I found that the plot was not smooth (as shown below): plot(density(test$V2), xlim=c(0,1000)) Is there away to make it smoother? Thanks a lot!! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] density plot not smooth
Thank you very much! I do need to learn more about R!! On Tuesday, March 17, 2015 9:26 PM, William Dunlap wrote: Fix Ace wrote What is the default "n"? 512: > length(density(rnorm(10^6))$x) [1] 512 > args(density.default) function (x, bw = "nrd0", adjust = 1, kernel = c("gaussian", "epanechnikov", "rectangular", "triangular", "biweight", "cosine", "optcosine"), weights = NULL, window = kernel, width, give.Rkern = FALSE, n = 512, from, to, cut = 3, na.rm = FALSE, ...) NULL > ?density # or ?density.default, should also tell you about its meaning Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 17, 2015 at 7:02 PM, Fix Ace wrote: Thank you for the email. What is the default "n"? Thanks! On Tuesday, March 17, 2015 4:06 PM, William Dunlap wrote: Increasing the value of 'n' given to density will give an estimate at more points so it will look smoother. Try n=2^18. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 17, 2015 at 12:06 PM, Fix Ace wrote: I have a dataset with 6187 elements, ranged from 3 to 104028. When I tried to examine only small range of data, I found that the plot was not smooth (as shown below): plot(density(test$V2), xlim=c(0,1000)) Is there away to make it smoother? Thanks a lot!! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] about model.matrix
I tried to run the sample code from R: dd <- data.frame(a = gl(3,4), b = gl(4,1,12)) a b 1 1 1 2 1 2 3 1 3 4 1 4 5 2 1 6 2 2 7 2 3 8 2 4 9 3 1 10 3 2 11 3 3 12 3 4 options("contrasts") model.matrix(~ a + b, dd)(Intercept) a2 a3 b2 b3 b4 11 0 0 0 0 0 21 0 0 1 0 0 31 0 0 0 1 0 41 0 0 0 0 1 51 1 0 0 0 0 61 1 0 1 0 0 71 1 0 0 1 0 81 1 0 0 0 1 91 0 1 0 0 0 10 1 0 1 1 0 0 11 1 0 1 0 1 0 12 1 0 1 0 0 1 when I tried to remove the intercept from the matrix, I used the following codemodel.matrix(~ 0+a + b, dd) a1 a2 a3 b2 b3 b41 1 0 0 0 0 02 1 0 0 1 0 03 1 0 0 0 1 04 1 0 0 0 0 15 0 1 0 0 0 06 0 1 0 1 0 07 0 1 0 0 1 08 0 1 0 0 0 19 0 0 1 0 0 010 0 0 1 1 0 011 0 0 1 0 1 012 0 0 1 0 0 1 when I tried to remove the intercept Here I noticed that, all levels of a, a1, a2, and a3, were included. I wonder how I can include the "b1" in the matrix as well? a1 a2 a3 b1 b2 b3 b4 1 1 0 0 1 0 0 0 2 1 0 0 0 1 0 0 3 1 0 0 0 0 1 0 4 1 0 0 0 0 0 1 5 0 1 0 1 0 0 0 6 0 1 0 0 1 0 0 7 0 1 0 0 0 1 0 8 0 1 0 0 0 0 1 9 0 0 1 1 0 0 0 10 0 0 1 0 1 0 0 11 0 0 1 0 0 1 0 12 0 0 1 0 0 0 1 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] about model.matrix
Thank you very much for the response. Then what does it mean? I am not a stat person, but have to use it for my project. :( Could you please recommend some readings about it? Thanks a lot! On Wednesday, April 1, 2015 10:58 AM, Michael Dewey wrote: This is really a question about statistics rather than R but see below On 01/04/2015 06:28, Fix Ace wrote: > I tried to run the sample code from R: > dd <- data.frame(a = gl(3,4), b = gl(4,1,12)) a b > 1 1 1 > 2 1 2 > 3 1 3 > 4 1 4 > 5 2 1 > 6 2 2 > 7 2 3 > 8 2 4 > 9 3 1 > 10 3 2 > 11 3 3 > 12 3 4 > options("contrasts") > model.matrix(~ a + b, dd)(Intercept) a2 a3 b2 b3 b4 > 1 1 0 0 0 0 0 > 2 1 0 0 1 0 0 > 3 1 0 0 0 1 0 > 4 1 0 0 0 0 1 > 5 1 1 0 0 0 0 > 6 1 1 0 1 0 0 > 7 1 1 0 0 1 0 > 8 1 1 0 0 0 1 > 9 1 0 1 0 0 0 > 10 1 0 1 1 0 0 > 11 1 0 1 0 1 0 > 12 1 0 1 0 0 1 > when I tried to remove the intercept from the matrix, I used the following > codemodel.matrix(~ 0+a + b, dd) > a1 a2 a3 b2 b3 b41 1 0 0 0 0 02 1 0 0 1 0 03 1 0 0 0 1 04 1 0 0 0 0 15 0 1 0 >0 0 06 0 1 0 1 0 07 0 1 0 0 1 08 0 1 0 0 0 19 0 0 1 0 0 010 0 0 1 1 0 011 0 0 >1 0 1 012 0 0 1 0 0 1 when I tried to remove the intercept > That got mangled but In your matrix below try forming the sum of a1+a2+a3 and the sum of b1+b2+b3+b4. I think you will find they are linearly related. > Here I noticed that, all levels of a, a1, a2, and a3, were included. I wonder > how I can include the "b1" in the matrix as well? a1 a2 a3 b1 b2 b3 b4 > 1 1 0 0 1 0 0 0 > 2 1 0 0 0 1 0 0 > 3 1 0 0 0 0 1 0 > 4 1 0 0 0 0 0 1 > 5 0 1 0 1 0 0 0 > 6 0 1 0 0 1 0 0 > 7 0 1 0 0 0 1 0 > 8 0 1 0 0 0 0 1 > 9 0 0 1 1 0 0 0 > 10 0 0 1 0 1 0 0 > 11 0 0 1 0 0 1 0 > 12 0 0 1 0 0 0 1 > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Michael http://www.dewey.myzen.co.uk/home.html [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] venn.diagram, error message: Incorrect number of elements
Hello, there, I have 6 dataset and trying to draw a venn.diagram using R VennDiagram package, but got this error message. Could anybody figure out why? Thanks === > library(VennDiagram) Loading required package: grid > head(A) V1 1 F_HO1 2 F_HO10001 3 F_HO10002 4 F_HO10003 5 F_HO10004 6 F_HO10005 > head(B) V1 1 F_HO1000 2 F_HO1 3 F_HO10001 4 F_HO10002 5 F_HO10003 6 F_HO10004 > head(C) V1 1 F_HO1 2 F_HO10001 3 F_HO10002 4 F_HO10003 5 F_HO10004 6 F_HO10005 > head(D) V1 1 F_HO1000 2 F_HO1 3 F_HO10001 4 F_HO10002 5 F_HO10003 6 F_HO10004 > head(E) V1 1 F_HO10001 2 F_HO10002 3 F_HO10004 4 F_HO10007 5 F_HO10008 6 F_HO10009 > head(F) V1 1 F_HO1000 2 F_HO1 3 F_HO10001 4 F_HO10002 5 F_HO10003 6 F_HO10004 > venn.diagram(x=list(A=A[,1], B=B[,1], C=C[,1], D=D[,1], E=E[,1], F=F[,1]), > filename="Venn-6.test.tiff", col="transparent", alpha=0.5, > fill=c("dodgerblue","goldenrod1","darkorange1","seagreen3","orchid3", > "green"), margin=0.2) Error: Incorrect number of elements. > [[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] venn.diagram, error message: Incorrect number of elements
Thanks! On Tuesday, July 29, 2014 3:08 PM, Sarah Goslee wrote: The venn.diagram() function in the package VennDiagram only works with sizes up to 5. That isn't horribly clear from the help file, but quite explicit in the code: if (0 == length(x) | length(x) > 5) { stop("Incorrect number of elements.", call. = FALSE) } If you really need 6, you could presumably look at the way that venn.diagram() works and add in your own 6-handling code. Sarah On Tue, Jul 29, 2014 at 11:11 AM, Fix Ace wrote: > Hello, there, > I have 6 dataset and trying to draw a venn.diagram using R VennDiagram > package, but got this error message. Could anybody figure out why? > > Thanks > === >> library(VennDiagram) > Loading required package: grid > >> head(A) > V1 > 1 F_HO1 > 2 F_HO10001 > 3 F_HO10002 > 4 F_HO10003 > 5 F_HO10004 > 6 F_HO10005 >> head(B) > V1 > 1 F_HO1000 > 2 F_HO1 > 3 F_HO10001 > 4 F_HO10002 > 5 F_HO10003 > 6 F_HO10004 >> head(C) > V1 > 1 F_HO1 > 2 F_HO10001 > 3 F_HO10002 > 4 F_HO10003 > 5 F_HO10004 > 6 F_HO10005 >> head(D) > V1 > 1 F_HO1000 > 2 F_HO1 > 3 F_HO10001 > 4 F_HO10002 > 5 F_HO10003 > 6 F_HO10004 >> head(E) > V1 > 1 F_HO10001 > 2 F_HO10002 > 3 F_HO10004 > 4 F_HO10007 > 5 F_HO10008 > 6 F_HO10009 >> head(F) > V1 > 1 F_HO1000 > 2 F_HO1 > 3 F_HO10001 > 4 F_HO10002 > 5 F_HO10003 > 6 F_HO10004 >> venn.diagram(x=list(A=A[,1], B=B[,1], C=C[,1], D=D[,1], E=E[,1], F=F[,1]), >> filename="Venn-6.test.tiff", col="transparent", alpha=0.5, >> fill=c("dodgerblue","goldenrod1","darkorange1","seagreen3","orchid3", >> "green"), margin=0.2) > Error: Incorrect number of elements. >> > > [[alternative HTML version deleted]] > > -- Sarah Goslee http://www.functionaldiversity.org [[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] circlize package: some error message
I recently tried to run some sample code from R package: circlize, and got an error message (please see below) = > library(circlize) > circos.genomicInitialize(df) > df = data.frame(name = c("TP53", "TP63", "TP73"), + start = c(7565097, 189349205, 3569084), + end = c(7590856, 189615068, 3652765), + stringsAsFactors = FALSE) > df name start end 1 TP53 7565097 7590856 2 TP63 189349205 189615068 3 TP73 3569084 3652765 > circos.genomicInitialize(df) > circos.clear() > circos.genomicInitialize(df, major.by = 1) Error in seq.default(xlim[1], 10^nchar(round(max(x2 - x1 + 1))), by = major.by) : wrong sign in 'by' argument === And my session information: > sessionInfo() R version 3.1.1 (2014-07-10) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=C [5] LC_MONETARY=en_US.utf8LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] circlize_0.1.0 loaded via a namespace (and not attached): [1] AnnotationDbi_1.26.0Biobase_2.24.0 BiocGenerics_0.10.0 [4] DBI_0.2-7 DESeq2_1.4.5GenomeInfoDb_1.0.2 [7] GenomicRanges_1.16.3IRanges_1.22.9 RColorBrewer_1.0-5 [10] RSQLite_0.11.4 Rcpp_0.11.2 RcppArmadillo_0.4.320.0 [13] XML_3.98-1.1XVector_0.4.0 annotate_1.42.1 [16] genefilter_1.46.1 geneplotter_1.42.0 grid_3.1.1 [19] lattice_0.20-29 locfit_1.5-9.1 parallel_3.1.1 [22] splines_3.1.1 stats4_3.1.1survival_2.37-7 [25] xtable_1.7-3 > === Wonder anyone could please help me out with this? Thank you very much for your time.:) [[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] how to process multiple data files using R loop
I have 16 files and would like to check the information of their first two lines, what I did: > ls(pattern="P_") [1] "P_3_utr_source_data" "P_5_utr_source_data" [3] "P_exon_per_gene_cds_source_data" "P_exon_per_gene_source_data" [5] "P_exon_source_data" "P_first_exon_oncds_source_data" [7] "P_first_intron_oncds_source_data" "P_first_intron_ongene_source_data" [9] "P_firt_exon_ongene_source_data" "P_gene_cds_source_data" [11] "P_gene_source_data" "P_intron_source_data" [13] "P_last_exon_oncds_source_data" "P_last_exon_ongene_source_data" [15] "P_last_intron_oncds_source_data" "P_last_intron_ongene_source_data" >for(i in ls(pattern="P_")){head(i, 2)} It obviously does not work since nothing came out What I would like to see for the output is : > head(P_3_utr_source_data,2) V1 1 1 2 1 > head(P_5_utr_source_data,2) V1 1 1 2 1 > . . . Could anybody help me with this? Thank you very much for your time:) [[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 process multiple data files using R loop
Thank you very much for all replies:) Here is my working code: for(i in ls(pattern="P_")){print(head(get(i),2))} On Monday, August 11, 2014 11:04 AM, Greg Snow <538...@gmail.com> wrote: In addition to the solution and comments that you have already received, here are a couple of additional comments: This is a variant on FAQ 7.21, if you had found that FAQ then it would have told you about the get function. The most important part of the answer in FAQ 7.21 is the last part where it says that it is better to use a list.� If all the objects of interest are related and you want to do the same or similar things to each one, then having them all stored in a single list can simplify things for the future.� You can collect all the objects into a single list using the mget command, e.g.: P_objects <- mget( ls(pattern='P_')) Now that they are in a list you can do the equivalent of your loop, but simpler with the lapply function, e.g.: lapply( P_objects, head, 2 ) And if you want to do other things with all these objects, such as save them, plot them, do a regression analysis on them, delete them, etc. then you can do that using lapply/sapply as well in a simpler way than looping. On Fri, Aug 8, 2014 at 12:25 PM, Fix Ace wrote: > I have 16 files and would like to check the information of their first two > lines, what I did: > > >> ls(pattern="P_") >� [1] "P_3_utr_source_data"� � � � � � � "P_5_utr_source_data" >� [3] "P_exon_per_gene_cds_source_data"� "P_exon_per_gene_source_data" >� [5] "P_exon_source_data"� � � � � � � � "P_first_exon_oncds_source_data" >� [7] "P_first_intron_oncds_source_data"� "P_first_intron_ongene_source_data" >� [9] "P_firt_exon_ongene_source_data"� � "P_gene_cds_source_data" > [11] "P_gene_source_data"� � � � � � � � "P_intron_source_data" > [13] "P_last_exon_oncds_source_data"� � "P_last_exon_ongene_source_data" > [15] "P_last_intron_oncds_source_data"� "P_last_intron_ongene_source_data" > > > >>for(i in ls(pattern="P_")){head(i, 2)} > > It obviously does not work since nothing came out > > What I would like to see for the output is : > >> head(P_3_utr_source_data,2) >� V1 > 1� 1 > 2� 1 >> head(P_5_utr_source_data,2) >� V1 > 1� 1 > 2� 1 >> > . > > . > . > > > > Could anybody help me with this? > > Thank you very much for your time:) >� � � � [[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.
[R] how to get the rows that satisfy a specific condition
Hello, there, I wonder if there is an easier way that I would only get the rows that satisfies some condition. For example:I have the following matrix, and I would like to output only the 3rd row and 4th row, since only these two rows contain the numbers greater than 11 > a [,1] [,2] [,3] [,4] [,5] [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20 > a>11 [,1] [,2] [,3] [,4] [,5] [1,] FALSE FALSE FALSE TRUE TRUE [2,] FALSE FALSE FALSE TRUE TRUE [3,] FALSE FALSE FALSE TRUE TRUE [4,] FALSE FALSE TRUE TRUE TRUE I have tried to use a[a>11, ] and it did not work. Thanks a lot for the help:) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to get the rows that satisfy a specific condition
Sorry for my confusing question. Thanks for all the inputs. I think Sven E. Templer gave the answer I needed... On Sunday, September 28, 2014 4:51 AM, Sven E. Templer wrote: in ?which read about arr.ind following jims assumption (column instead of row indices is what you want) this also works: m <- matrix(1:20,4) unique(which(m>11, arr.ind = T)[,"col"]) On 27 September 2014 12:23, Jim Lemon wrote: > On Fri, 26 Sep 2014 10:15:14 PM Fix Ace wrote: >> Hello, there, >> I wonder if there is an easier way that I would only get the rows that >> satisfies some condition. For example:I have the following matrix, and I >> would like to output only the 3rd row and 4th row, since only these two >> rows contain the numbers greater than 11 >> > a >> >> [,1] [,2] [,3] [,4] [,5] >> [1,] 1 5 9 13 17 >> [2,] 2 6 10 14 18 >> [3,] 3 7 11 15 19 >> [4,] 4 8 12 16 20 >> >> > a>11 >> >> [,1] [,2] [,3] [,4] [,5] >> [1,] FALSE FALSE FALSE TRUE TRUE >> [2,] FALSE FALSE FALSE TRUE TRUE >> [3,] FALSE FALSE FALSE TRUE TRUE >> [4,] FALSE FALSE TRUE TRUE TRUE >> I have tried to use a[a>11, ] and it did not work. >> Thanks a lot for the help:) > > Hi Fix Ace, > I have to admit that I am unfamiliar with the system of arithmetic that > you are employing in the above example. In no system with which I am > conversant are 13, 17, 14 and 18 less than or equal to 11. I can only > offer the desperate conjecture that you want the third to fifth columns of > the matrix rather than the third and fourth rows. If this wild surmise > happens to be the case, I suggest that you try this: > > testmat[,apply(testmat,2,function(x) return(max(x) > 11))] > > Jim > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help with gradient boxplot
Hello, there, I will like to fill the boxplot with gradient color, as exampled below: Can anyone help me figure out what package I should go with? Thank you very much for any inputs! Kind regards, Ace __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] dendrogram adjustment in heatmap.2
Dear R Community, Is there a way to adjust the line width of the dendrogram in heat map.2 function? I tried "lwd", but it didn't work... Also, is there a way to adjust the general height/width/position of the dendrogram using heatmap.2 function? I feel the portion of the dendrogram is huge compared with the overall graph. I would like to squeeze them a bit. Thank you very much for any inputs! Kind regards, Ace [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error message for function: lmer (from lme4 package)
Dear R Community, My data have 3 conditions and each condition has 6 replicates. I am trying to fit my data for a linear mixed model using the lmer function from lme4 package to find the random effects of the replicates; however, I got the error message. Here are the example codes: >example.3=data.frame(levels=as.numeric(XXX[,c(4)]),replicate=rep(c("0","1","2","3","4","5"),3),conditions=c(rep("11",6),rep("12",6),rep("13",6)))> > example.3 levels replicate conditions1 43. 0 112 >42.0942 1 113 57.8131 2 114 57.1726 >3 115 77.8678 4 116 44.7578 5 117 >69.5078 0 128 52.0581 1 129 40.0602 >2 1210 45.5487 3 1211 43.6201 4 1212 >60.4939 5 1213 64.1932 0 1314 53.4055 >1 1315 59.6701 2 1316 52.6922 3 1317 >53.8712 4 1318 60.2770 5 13> >m.example.3=lmer(as.numeric(levels)~conditions+(conditions|replicate),data=example.3)Error: > number of observations (=18) <= number of random effects (=18) for term >(conditions | replicate); the random-effects parameters and the residual >variance (or scale parameter) are probably unidentifiable> Could anyone help me figure out how to fix the issue? Thank you very much for any inputs! Ace [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error message for function: lmer (from lme4 package)
Hi, David, Thank you very much for getting back to me! Sorry about the messy code example. I am re-posting here (including the error message): > example.3=data.frame(levels=as.numeric(XXX[,c(4)]),replicate=rep(c("0","1","2","3","4","5"),3),conditions=c(rep("11",6),rep("12",6),rep("13",6)))> > example.3 levels replicate conditions1 43. 0 112 > 42.0942 1 113 57.8131 2 114 57.1726 > 3 115 77.8678 4 116 44.7578 5 117 > 69.5078 0 128 52.0581 1 129 40.0602 > 2 1210 45.5487 3 1211 43.6201 4 1212 > 60.4939 5 1213 64.1932 0 1314 53.4055 > 1 1315 59.6701 2 1316 52.6922 3 1317 > 53.8712 4 1318 60.2770 5 13> > m.example.3=lmer(as.numeric(levels)~conditions+(conditions|replicate),data=example.3)Error: > number of observations (=18) <= number of random effects (=18) for term > (conditions | replicate); the random-effects parameters and the residual > variance (or scale parameter) are probably unidentifiable> Please let me know if it is readable this time. Again, many thanks for your time and please help me fix the issue. Kind regards, Ace On Tuesday, November 14, 2017 12:19 PM, David Winsemius wrote: > On Nov 14, 2017, at 5:13 AM, Fix Ace via R-help wrote: > > Dear R Community, > My data have 3 conditions and each condition has 6 replicates. I am trying to > fit my data for a linear mixed model using the lmer function from lme4 > package to find the random effects of the replicates; Better venue for this question might be SIG-mixed-models. See the link avaialble at the bottom of every posting from rhelp: https://stat.ethz.ch/mailman/listinfo/r-help: > however, I got the error message. Here are the example codes: >> example.3=data.frame(levels=as.numeric(XXX[,c(4)]),replicate=rep(c("0","1","2","3","4","5"),3),conditions=c(rep("11",6),rep("12",6),rep("13",6)))> >> example.3 levels replicate conditions1 43. 0 112 >> 42.0942 1 113 57.8131 2 114 57.1726 3 >> 115 77.8678 4 116 44.7578 5 117 69.5078 >> 0 128 52.0581 1 129 40.0602 2 >> 1210 45.5487 3 1211 43.6201 4 1212 60.4939 >> 5 1213 64.1932 0 1314 53.4055 1 1315 >> 59.6701 2 1316 52.6922 3 1317 53.8712 4 >> 1318 60.2770 5 13> >> m.example.3=lmer(as.numeric(levels)~conditions+(conditions|replicate),data=example.3)Error: >> number of observations (=18) <= number of random effects (=18) for term >> (conditions | replicate); the random-effects parameters and the residual >> variance (or scale parameter) are probably unidentifiable> > Could anyone help me figure out how to fix the issue? > Thank you very much for any inputs! > Ace > > [[alternative HTML version deleted]] Complete mess. If you haven't yet been advised to posting in plain text, then this should be your wakeup call. If you have, then why are you ignoring sensible advice? > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 'Any technology distinguishable from magic is insufficiently advanced.' -Gehm's Corollary to Clarke's Third Law [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error message for function: lmer (from lme4 package)
Hi, Bert, Thank you very much for the comments and suggestions! Ace On Wednesday, November 15, 2017 10:44 AM, Bert Gunter wrote: Always cc the list, which I have done here. I am not a (free) private consultant, nor do I have all the answers. Based on what you sent me, which is not what you have previously posted, you failed to load the lme3 package. See ?library. As for the appropriateness of your modeling, you should do what David already suggested and post to the r-sig-mixed-models list instead. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Nov 15, 2017 at 5:09 AM, Fix Ace wrote: Hi, Bert, Sorry about that! David seemed to be able to read the post since he replied. Here I just email you the sample code and error message: > example.3=data.frame(levels= as.numeric(XXX[,c(4)]), > replicate=rep(c("0","1","2"," 3","4","5"),3),conditions=c( > rep("11",6),rep("12",6),rep(> example.3 levels replicate conditions1 > 43. 0 112 42.0942 1 113 57.8131 > 2 114 57.1726 3 115 77.8678 4 116 > 44.7578 5 117 69.5078 0 128 52.0581 > 1 129 40.0602 2 1210 45.5487 3 1211 > 43.6201 4 1212 60.4939 5 1213 64.1932 > 0 1314 53.4055 1 1315 59.6701 2 1316 > 52.6922 3 1317 53.8712 4 1318 60.2770 > 5 13> m.example.3=lmer(as.numeric( levels)~conditions+( > conditions|replicate),data= example.3)Error in lmer(as.numeric(levels) ~ > conditions + (conditions | replicate), : could not find function "lmer"> Hopefully you could read it and provide some comments! Thank you very much for your time. Kind regards, Ace On Tuesday, November 14, 2017 6:12 PM, Bert Gunter wrote: Still a complete mess! Post in **plain text**. This should be an option in your email software. Please seek local help if you cannot figure out how to do this. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Nov 14, 2017 at 12:49 PM, Fix Ace via R-help wrote: Hi, David, Thank you very much for getting back to me! Sorry about the messy code example. I am re-posting here (including the error message): > example.3=data.frame(levels= as.numeric(XXX[,c(4)]), > replicate=rep(c("0","1","2"," 3","4","5"),3),conditions=c( > rep("11",6),rep("12",6),rep(" 13",6)))> example.3 levels replicate > conditions1 43. 0 112 42.0942 1 113 > 57.8131 2 114 57.1726 3 115 77.8678 > 4 116 44.7578 5 117 69.5078 0 128 > 52.0581 1 129 40.0602 2 1210 45.5487 > 3 1211 43.6201 4 1212 60.4939 5 1213 > 64.1932 0 1314 53.4055 1 1315 59.6701 > 2 1316 52.6922 3 1317 53.8712 4 1318 > 60.2770 5 13> m.example.3=lmer(as.numeric( > levels)~conditions+( conditions|replicate),data= example.3)Error: number of > observations (=18) <= number of random effects (=18) for term (conditions | > replicate); the random-effects parameters and the residual variance (or scale > parameter) are probably unidentifiable> Please let me know if it is readable this time. Again, many thanks for your time and please help me fix the issue. Kind regards, Ace On Tuesday, November 14, 2017 12:19 PM, David Winsemius wrote: > On Nov 14, 2017, at 5:13 AM, Fix Ace via R-help wrote: > > Dear R Community, > My data have 3 conditions and each condition has 6 replicates. I am trying to > fit my data for a linear mixed model using the lmer function from lme4 > package to find the random effects of the replicates; Better venue for this question might be SIG-mixed-models. See the link avaialble at the bottom of every posting from rhelp: https://stat.ethz.ch/mailman/ listinfo/r-help: > however, I got the error message. Here are the example codes: >> example.3=data.frame(levels= as.numeric(XXX[,c(4)]), >> replicate=rep(c("0","1","2"," 3","4","5"),3),
[R] help with the plot overlay
Dear R Community, I recently read an article and found a plot as attached. It has scatterplot, barplot, and error bar. Could anyone help me to figure out what package I can use in R to generate such plot? Thank you very much for any inputs! Kind regards, Ace __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 with the plot overlay
Hi, JIm, Thank you so much! Such a convenient tool! A. On Sunday, February 4, 2018 9:59 PM, Jim Lemon wrote: Hi Ace, You can do it with plotrix: library(plotrix) barpos<-barp(c(1,5,38),width=0.5,col=c("white","lightgray","darkgray"),ylim=c(0,70)) ehplot(c(1,0.8,0.9,0.8,1.1,1,4,3,5,14,3,2,32,27,33,30,50,61), c(1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3),median=FALSE,add=TRUE,cex=2, pch=21,bg="white") dispersion(barpos$x,barpos$y,c(0.1,1,5),lwd=2,arrow.cap=0.03) lines(c(barpos$x[2],barpos$x[2],barpos$x[3],barpos$x[3]),c(18,63,63,62)) lines(c(barpos$x[1],barpos$x[1],barpos$x[3],barpos$x[3]),c(4,66,66,65)) text(2,68,"**",cex=2) text(2.5,64.5,"**",cex=2) Jim On Mon, Feb 5, 2018 at 8:56 AM, Fix Ace via R-help wrote: > Dear R Community, > I recently read an article and found a plot as attached. It has scatterplot, > barplot, and error bar. Could anyone help me to figure out what package I can > use in R to generate such plot? > Thank you very much for any inputs! > Kind regards, > Ace > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] prcomp: Error in La.svd(x, nu, nv): error code 1 from Lapack routine "dgesdd"
Dear R community, I have a data matrix (531X314), and would like to apply the prcomp. However, I got this error Lapack message. I am using R3.2.2. I googled a bit and found that it might be related to converge issue. Just wonder if there is a way to get around it? Thank you very much! Ace On Thursday, December 29, 2016 11:44 AM, Ista Zahn wrote: Use coord_fixed() --Ista On Thu, Dec 29, 2016 at 9:59 AM, Fix Ace via R-help wrote: > > > > Hello, there, > What exactly does "expand" do for this function? > I followed the examples from the manual to get a plot: > > d <- ggplot(subset(diamonds, carat > 1), aes(cut, clarity)) +geom_jitter() > > I would like to have all the dots in a square instead of rectangular range. > When I applied d + scale_x_discrete(expand=c(1,1)) and d + > scale_x_discrete(expand=c(1,0)), I got the same plot (different from the > original one though). > Could anyone help me to figure out how to use this argument? > Thank you very much! > Ace > > > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 with read.csv() for files with different number of columns
Dear R community, I have a text file (test.txt) with different number of columns: 0610007P14Rik%%% Tcf19 Gtf2i 0610010O12Rik%%% Ivns1abp Etv6 111G20Rik%%% Nmi 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 173E16Rik%%% Ascl2 Ifnar2 1700028J19Rik%%% Musk Nfe2l3 1810011O10Rik%%% Ppp1r13b Bpnt1 Cdkn2c Foxc1 Sox10 Smarca2 1810019D21Rik%%% Asb8 1810037I17Rik%%% Zfp612 1810055G02Rik%%% Nkx2-3 Maged1 Runx1 Ugp2 Elk4 Spdef Tcf19 Isl2 Gtf2i Ctnnbl1 Tcea3 Ank2 Zfp612 Creb3l1 Nupr1 3632451O06Rik Creb3l4 Lass6 I wold like to read it into R using > test=read.csv("test.txt",sep="\t",header=FALSE) However, when I check the r object "test", I found that all the rows have 5 columns: > test V1 V2 V3 V4 V51 > 0610007P14Rik%%% Tcf19 Gtf2i 2 0610010O12Rik%%% > Ivns1abp Etv6 3 111G20Rik%%% Nmi > 4 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 5 > 173E16Rik%%% Ascl2 Ifnar2 6 1700028J19Rik%%% > Musk Nfe2l3 7 1810011O10Rik%%% Ppp1r13b Bpnt1 > Cdkn2c Foxc18 Sox10 Smarca2 9 > 1810019D21Rik%%% Asb8 10 1810037I17Rik%%% > Zfp612 11 1810055G02Rik%%% Nkx2-3 Maged1 > Runx1 Ugp212 Elk4 Spdef Tcf19 Isl2 Gtf2i13 > Ctnnbl1 Tcea3 Ank2 Zfp612 Creb3l114 Nupr1 > 3632451O06Rik Creb3l4 Lass6 Basically it breaks some rows into more than one rows. For example, row 7 in the original record becomes two rows. Looks like the "test" always has 5 columns. How does this happen? How should I fix it to make one record into one two in R object? Thank you very much! Ace [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 with read.csv() for files with different number of columns
Hi, Jim, Thank you very much for pointing out the format issue. Here is the original text: ===I have a text file (test.txt) with different number of columns: 0610007P14Rik%%% Tcf19 Gtf2i 0610010O12Rik%%% Ivns1abp Etv6 111G20Rik%%% Nmi 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 173E16Rik%%% Ascl2 Ifnar2 1700028J19Rik%%% Musk Nfe2l3 1810011O10Rik%%% Ppp1r13b Bpnt1 Cdkn2c Foxc1 Sox10 Smarca2 1810019D21Rik%%% Asb8 1810037I17Rik%%% Zfp612 1810055G02Rik%%% Nkx2-3 Maged1 Runx1 Ugp2 Elk4 Spdef Tcf19 Isl2 Gtf2i Ctnnbl1 Tcea3 Ank2 Zfp612 Creb3l1 Nupr1 3632451O06Rik Creb3l4 Lass6 I wold like to read it into R using > test=read.csv("test.txt",sep="\t",header=FALSE) However, when I check the r object "test", I found that all the rows have 5 columns: > test V1 V2 V3 V4 V51 > 0610007P14Rik%%% Tcf19 Gtf2i 2 0610010O12Rik%%% > Ivns1abp Etv6 3 111G20Rik%%% Nmi > 4 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 5 > 173E16Rik%%% Ascl2 Ifnar2 6 1700028J19Rik%%% > Musk Nfe2l3 7 1810011O10Rik%%% Ppp1r13b Bpnt1 > Cdkn2c Foxc18 Sox10 Smarca2 9 > 1810019D21Rik%%% Asb8 10 1810037I17Rik%%% > Zfp612 11 1810055G02Rik%%% Nkx2-3 Maged1 > Runx1 Ugp212 Elk4 Spdef Tcf19 Isl2 Gtf2i13 > Ctnnbl1 Tcea3 Ank2 Zfp612 Creb3l114 Nupr1 > 3632451O06Rik Creb3l4 Lass6 Basically it breaks some rows into more than one rows. For example, row 7 in the original record becomes two rows. Looks like the "test" always has 5 columns. How does this happen? How should I fix it to make one record into one two in R object? == Please let me know if it is readable now. Thank you very much for your time! Kind regards, Ace On Sunday, August 27, 2017 7:25 PM, Jim Lemon wrote: Hi Ace, As your example seems to have spaces as separators, testdf<-read.table("test.txt",header=FALSE,fill=TRUE, col.names=paste("V",1:14,sep=""),stringsAsFactors=FALSE) By specifying the number of columns with "col.names" and using "fill=TRUE" you can get a data frame with zero length strings where values are missing in the input file. Jim On Mon, Aug 28, 2017 at 6:25 AM, Fix Ace via R-help wrote: > Dear R community, > I have a text file (test.txt) with different number of columns: > 0610007P14Rik%%% Tcf19 Gtf2i 0610010O12Rik%%% Ivns1abp Etv6 111G20Rik%%% > Nmi 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 173E16Rik%%% Ascl2 Ifnar2 > 1700028J19Rik%%% Musk Nfe2l3 1810011O10Rik%%% Ppp1r13b Bpnt1 Cdkn2c Foxc1 > Sox10 Smarca2 1810019D21Rik%%% Asb8 1810037I17Rik%%% Zfp612 1810055G02Rik%%% > Nkx2-3 Maged1 Runx1 Ugp2 Elk4 Spdef Tcf19 Isl2 Gtf2i Ctnnbl1 Tcea3 Ank2 > Zfp612 Creb3l1 Nupr1 3632451O06Rik Creb3l4 Lass6 > I wold like to read it into R using > > test=read.csv("test.txt",sep="\t",header=FALSE) > However, when I check the r object "test", I found that all the rows have 5 > columns: >> test V1 V2 V3 V4 V51 >> 0610007P14Rik%%% Tcf19 Gtf2i 2 0610010O12Rik%%% >> Ivns1abp Etv6 3 111G20Rik%%% Nmi >> 4 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 5 >> 173E16Rik%%% Ascl2 Ifnar2 6 1700028J19Rik%%% >> Musk Nfe2l3 7 1810011O10Rik%%% Ppp1r13b Bpnt1 Cdkn2c >> Foxc18 Sox10 Smarca2 9 >> 1810019D21Rik%%% Asb8 10 1810037I17Rik%%% >> Zfp612 11 1810055G02Rik%%% Nkx2-3 Maged1 >> Runx1 Ugp212 Elk4 Spdef Tcf19 Isl2 Gtf2i13 >> Ctnnbl1 Tcea3 Ank2 Zfp612 Creb3l114 Nupr1 3632451O06Rik >> Creb3l4 Lass6 > Basically it breaks some rows into more than one rows. For example, row 7 in > the original record becomes two rows. Looks like the "test" always has 5 > columns. > How does this happen? How should I fix it to make one record into one two in > R object? > Thank you very much! > Ace > > > > > > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-con
Re: [R] help with read.csv() for files with different number of columns
Thank you very much! Looks like I have to know the length of each record ahead of time. Ace On Monday, August 28, 2017 12:56 AM, Jim Lemon wrote: Hi Ace, With tabs as separators: testdf<-read.table("test.txt",header=FALSE,fill=TRUE,sep="\t", col.names=paste("V",1:19,sep=""),stringsAsFactors=FALSE) Also note that I got the number of columns wrong the first time. Jim On Mon, Aug 28, 2017 at 12:56 PM, Fix Ace wrote: > Hi, Jim, > > Thank you very much for pointing out the format issue. Here is the original > text: > > === > I have a text file (test.txt) with different number of columns: > > 0610007P14Rik%%% Tcf19 Gtf2i > 0610010O12Rik%%% Ivns1abp Etv6 > 111G20Rik%%% Nmi > 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 > 173E16Rik%%% Ascl2 Ifnar2 > 1700028J19Rik%%% Musk Nfe2l3 > 1810011O10Rik%%% Ppp1r13b Bpnt1 Cdkn2c Foxc1 Sox10 Smarca2 > 1810019D21Rik%%% Asb8 > 1810037I17Rik%%% Zfp612 > 1810055G02Rik%%% Nkx2-3 Maged1 Runx1 Ugp2 Elk4 Spdef Tcf19 Isl2 Gtf2i > Ctnnbl1 Tcea3 Ank2 Zfp612 Creb3l1 Nupr1 3632451O06Rik Creb3l4 Lass6 > > I wold like to read it into R using > >> test=read.csv("test.txt",sep="\t",header=FALSE) > > However, when I check the r object "test", I found that all the rows have 5 > columns: > >> test > V1 V2 V3 V4 V5 > 1 0610007P14Rik%%% Tcf19 Gtf2i > 2 0610010O12Rik%%% Ivns1abp Etv6 > 3 111G20Rik%%% Nmi > 4 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 > 5 173E16Rik%%% Ascl2 Ifnar2 > 6 1700028J19Rik%%% Musk Nfe2l3 > 7 1810011O10Rik%%% Ppp1r13b Bpnt1 Cdkn2c Foxc1 > 8 Sox10 Smarca2 > 9 1810019D21Rik%%% Asb8 > 10 1810037I17Rik%%% Zfp612 > 11 1810055G02Rik%%% Nkx2-3 Maged1 Runx1 Ugp2 > 12 Elk4 Spdef Tcf19 Isl2 Gtf2i > 13 Ctnnbl1 Tcea3 Ank2 Zfp612 Creb3l1 > 14 Nupr1 3632451O06Rik Creb3l4 Lass6 > > Basically it breaks some rows into more than one rows. For example, row 7 in > the original record becomes two rows. Looks like the "test" always has 5 > columns. > > How does this happen? How should I fix it to make one record into one two in > R object? > > == > > Please let me know if it is readable now. Thank you very much for your time! > > Kind regards, > > Ace > > > On Sunday, August 27, 2017 7:25 PM, Jim Lemon wrote: > > > Hi Ace, > As your example seems to have spaces as separators, > > testdf<-read.table("test.txt",header=FALSE,fill=TRUE, > col.names=paste("V",1:14,sep=""),stringsAsFactors=FALSE) > > By specifying the number of columns with "col.names" and using > "fill=TRUE" you can get a data frame with zero length strings where > values are missing in the input file. > > Jim > > On Mon, Aug 28, 2017 at 6:25 AM, Fix Ace via R-help > wrote: >> Dear R community, >> I have a text file (test.txt) with different number of columns: >> 0610007P14Rik%%% Tcf19 Gtf2i 0610010O12Rik%%% Ivns1abp Etv6 >> 111G20Rik%%% Nmi 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 173E16Rik%%% >> Ascl2 Ifnar2 1700028J19Rik%%% Musk Nfe2l3 1810011O10Rik%%% Ppp1r13b Bpnt1 >> Cdkn2c Foxc1 Sox10 Smarca2 1810019D21Rik%%% Asb8 1810037I17Rik%%% Zfp612 >> 1810055G02Rik%%% Nkx2-3 Maged1 Runx1 Ugp2 Elk4 Spdef Tcf19 Isl2 Gtf2i >> Ctnnbl1 Tcea3 Ank2 Zfp612 Creb3l1 Nupr1 3632451O06Rik Creb3l4 Lass6 >> I wold like to read it into R using >> > test=read.csv("test.txt",sep="\t",header=FALSE) >> However, when I check the r object "test", I found that all the rows have >> 5 columns: >>> test V1 V2 V3 V4 V51 >>> 0610007P14Rik%%% Tcf19 Gtf2i 2 0610010O12Rik%%% >>> Ivns1abp Etv6 3 111G20Rik%%% Nmi >>> 4 1500015O10Rik%%% Foxi1 Ascl3 Sirt3 5 173E16Rik%%% >>> Ascl2 Ifnar2 6 1700028J19Rik%%% Musk Nfe2l3 >>> 7 1810011O10Rik%%% Ppp1r13b Bpnt1 Cdkn2c Foxc18 Sox10 >>> Smarca2 9 1810019D21Rik%%% Asb8 >>> 10 1810037I17Rik%%% Zfp612 11 1810055G02Rik%%% >>> Nkx2-3 Maged1 Runx1 Ugp212 Elk4 Spdef Tcf19 Isl2 >>> Gtf2i13 Ctnnbl1 Tcea3 Ank2 Zfp612 Creb3l114 >>> Nupr1 3632451O06Rik Creb3l4 Lass6 >> Basically it breaks some rows into more than one rows. For example, row 7 >> in the original r
[R] error with subtree()
Dear R community, I would like to plot a partial hclust output, so I am looking for a subtree function that would return an tree structure I can plot. I ran the test code of subtree following the instruction on http://finzi.psych.upenn.edu/library/extracat/html/subtree.html However, an error message popped up: > library(extracat) Attaching package: ‘extracat’ The following object is masked _by_ ‘.GlobalEnv’: subtreehc <- hclust(dist(USArrests), "ave")> > hcs <- subtree(hc, k = 7)Error in subtree(hc, k = 7) : unused argument (k = 7) === Can anyone help me what happened here? And what should I do with it? Thank you very much! Ace [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] pheatmap: incomplete figure
Thank you so much for the reply! I thought the file would automatically adjust accordingly. But I just checked and found pheatmap does has width as parameter! Ace On Monday, September 18, 2017 3:00 PM, David Winsemius wrote: > On Sep 18, 2017, at 9:26 AM, Fix Ace via R-help wrote: > > Dear R Community, > I tried to generate heatmap for a matrix of 1500 columns by 106 rows using > the following R script: >> pheatmap(tf.vs.DE.1.removeAllZeroCol, fontsize=3,border_color=NA) > and got the graph (as attached Fig 1) > > Since the column labels appear very crowded, I tried to increase the > cellwidth to stretch the graph horizontally. The idea was to show the graph > section by section, but with clear/readable column labels (not overlapped > labels). > So I typed: >> pheatmap(tf.vs.DE.1.removeAllZeroCol, >> fontsize=3,cellwidth=3,cellheight=3,border_color=NA) > However, this time I only got middle part of the original heatmap (as > attached Fig 2) > I wonder if there is way I could output the whole graph after such horizontal > stretch. If not, how do I get the left end of the graph. > Why not define a graphics device that is wider? -- David Winsemius Alameda, CA, USA 'Any technology distinguishable from magic is insufficiently advanced.' -Gehm's Corollary to Clarke's Third Law [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 pass multiple pattern varibles to grep()
Hello, there, My patterns are defined by variables, for example:z="h"v="x" I have a vector: a=c("th","mx","t") I would like to find elements in vector a that contain either "h", or "x" grep("h|x", a) apparently works. However, when I tried: grep(z|v,a), it did not work. Can anyone help how to handle such situation? Thanks. Ace On Wednesday, March 18, 2015 5:52 PM, Fix Ace wrote: Thank you very much! I do need to learn more about R!! On Tuesday, March 17, 2015 9:26 PM, William Dunlap wrote: Fix Ace wrote What is the default "n"? 512: > length(density(rnorm(10^6))$x) [1] 512 > args(density.default) function (x, bw = "nrd0", adjust = 1, kernel = c("gaussian", "epanechnikov", "rectangular", "triangular", "biweight", "cosine", "optcosine"), weights = NULL, window = kernel, width, give.Rkern = FALSE, n = 512, from, to, cut = 3, na.rm = FALSE, ...) NULL > ?density # or ?density.default, should also tell you about its meaning Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 17, 2015 at 7:02 PM, Fix Ace wrote: Thank you for the email. What is the default "n"? Thanks! On Tuesday, March 17, 2015 4:06 PM, William Dunlap wrote: Increasing the value of 'n' given to density will give an estimate at more points so it will look smoother. Try n=2^18. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 17, 2015 at 12:06 PM, Fix Ace wrote: I have a dataset with 6187 elements, ranged from 3 to 104028. When I tried to examine only small range of data, I found that the plot was not smooth (as shown below): plot(density(test$V2), xlim=c(0,1000)) Is there away to make it smoother? Thanks a lot!! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 use vector of values to change row order of a heatmap
Hello, there, R document for heatmap says that Rowv could be a vector of values to specify the row order. However, I couldn't figure out how to apply it. A simple example here:> b=as.data.frame(matrix(c(3,4,5,8,9,10,13,14,15,27,19,20),3,4)) > b V1 V2 V3 V4 1 3 8 13 27 2 4 9 14 19 3 5 10 15 20 > row.names(b)=c("a","b","c") > b V1 V2 V3 V4 a 3 8 13 27 b 4 9 14 19 c 5 10 15 20 > heatmap(as.matrix(b)) What I got: Now I would like to put row "a" to the top row, how do I do that?I tried provide a vector of values (all the possible combination of 1,2,3) to Rowv, "a" is always stay at the bottom Any input would be very helpful! Ace __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 use vector of values to change row order of a heatmap
Hello, there, R document for heatmap says that Rowv could be a vector of values to specify the row order. However, I couldn't figure out how to apply it. A simple example here:> b=as.data.frame(matrix(c(3,4,5,8,9,10,13,14,15,27,19,20),3,4)) > b V1 V2 V3 V4 1 3 8 13 27 2 4 9 14 19 3 5 10 15 20 > row.names(b)=c("a","b","c") > b V1 V2 V3 V4 a 3 8 13 27 b 4 9 14 19 c 5 10 15 20 > heatmap(as.matrix(b)) What I got: "a" stays at the bottom of the heatmap. Now I would like to put row "a" to the top row, how do I do that?I tried provide a vector of values (all the possible combination of 1,2,3) to Rowv, "a" is always stay at the bottom Any input would be very helpful! Thanks. Ace [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [FORGED] help with gradient boxplot
Hi, Paul, Thank you very much for your reply. I tried your sample code, but did not get gradient filling (still empty box). And many warnings:1: In checkAttrs(attrs, eltName) : Removing non-SVG attribute name(s): fill, fill-opacity 2: In checkAttrs(attrs, eltName) : Removing non-SVG attribute name(s): fill, fill-opacity 3: In checkAttrs(attrs, eltName) : Removing non-SVG attribute name(s): fill, fill-opacity 4: In checkAttrs(attrs, eltName) : Removing non-SVG attribute name(s): fill, fill-opacity 5: In checkAttrs(attrs, eltName) : ... I saw the figure in an article, and so I don't have to script. I am actually trying to generate the similar figure for my own data. Any other thoughts? Thanks. Ace On Tuesday, December 6, 2016 7:43 PM, Paul Murrell wrote: Hi 'gridSVG' might be one way to get this. For example ... library(lattice) # Draw boxplot (with a package that sits on top of 'grid') bwplot(voice.part ~ height, data=singer, xlab="Height (inches)", horizontal=FALSE) library(grid) grid.ls() # Looks like boxes are called bwplot.box.polygon library(gridSVG) # Define linear gradient fill <- linearGradient(c("blue", "red"), x0=.5, x1=.5, gradientUnits="coords") # Register gradient now so it applies to the whole page registerGradientFill("br", fill) # Fill each box with gradient grid.gradientFill("bwplot.box.polygon", label=rep("br", 17), grep=TRUE, group=FALSE) # Generate SVG version "Rplots.svg" # (where the gradient will actually be visible) grid.export() Does that help ? Paul On 07/12/16 09:14, Fix Ace wrote: > Hello, there, > I will like to fill the boxplot with gradient color, as exampled below: > > Can anyone help me figure out what package I should go with? > Thank you very much for any inputs! > Kind regards, > Ace > > > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [FORGED] help with gradient boxplot
Hi, Paul, Thank you very much! It works this time with "strict=FALSE" option. Another relevant question: how did you figure out that boxes in boxplot are called "bwplot.box.polygon". If I am trying to make a gradient filling for barplot of other plots, how would I define grobs? Thanks!! Ace On Thursday, December 8, 2016 5:24 PM, Paul Murrell wrote: Hi You could try ... grid.export(..., strict=FALSE) ... and/or install the latest gridSVG version from R-Forge ... https://r-forge.r-project.org/R/?group_id=1025 Paul [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [FORGED] help with gradient boxplot
Hi, Paul, Thank you so much for this further clarification! Ace On Sunday, December 11, 2016 2:09 PM, Paul Murrell wrote: Hi Great to hear you have it working. Figuring out the names of grobs takes two things: 1. someone has to name the grobs 2. grid.ls() The reason why I did my example using 'lattice' is because 'lattice' names all of its grobs. There is a document ... http://lattice.r-forge.r-project.org/Vignettes/src/naming-scheme/namingScheme.pdf ... that describes the 'lattice' naming scheme. Paul On 10/12/16 10:39, Fix Ace wrote: > Hi, Paul, > > Thank you very much! It works this time with "strict=FALSE" option. > > Another relevant question: > > how did you figure out that boxes in boxplot are called > "bwplot.box.polygon". If I am trying to make a gradient filling for > barplot of other plots, how would I define grobs? > > Thanks!! > > Ace > > > > > > On Thursday, December 8, 2016 5:24 PM, Paul Murrell > wrote: > > > Hi > > You could try ... > > grid.export(..., strict=FALSE) > > ... and/or install the latest gridSVG version from R-Forge ... > > https://r-forge.r-project.org/R/?group_id=1025 > > Paul > > -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] ggplot2 package: argument of expand with scale_x_discrete()
Hello, there, What exactly does "expand" do for this function? I followed the examples from the manual to get a plot: d <- ggplot(subset(diamonds, carat > 1), aes(cut, clarity)) +geom_jitter() I would like to have all the dots in a square instead of rectangular range. When I applied d + scale_x_discrete(expand=c(1,1)) and d + scale_x_discrete(expand=c(1,0)), I got the same plot (different from the original one though). Could anyone help me to figure out how to use this argument? Thank you very much! Ace [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] princomp() output loadings component missing
Hello, there, I did a test run for this princomp() function using USArrests data. The R document says that the output loadings contain the eigenvector matrix. When I looked at this matrix, I found that a missing item for Comp.4 > p3=princomp(USArrests, cor=TRUE )> p3$loadings Loadings: Comp.1 Comp.2 Comp.3 Comp.4Murder -0.536 0.418 -0.341 0.649Assault -0.583 0.188 -0.268 -0.743UrbanPop -0.278 -0.873 -0.378 0.134Rape -0.543 -0.167 0.818 Comp.1 Comp.2 Comp.3 Comp.4SS loadings 1.00 1.00 1.00 1.00Proportion Var 0.25 0.25 0.25 0.25Cumulative Var 0.25 0.50 0.75 1.00 How should I explain this? Thanks. Ace [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] princomp() output loadings component missing
Thank you very much! Ace On Sunday, January 29, 2017 4:13 PM, Ben Tupper wrote: Hi, Check out the detailed explanation in the 'Value' section of ?princomp - in particular for 'loadings'. It will send you to ?loadings where it explains why that one element appears to be missing. If you really want to see the missing value try... p3$loadings['Rape', 'Comp.4'] ... or even ... unclass(p3$loadings) Don't forget that this email list works best when messages are send in plain text, and it works poorly for html or rich text. Check the settings in your email client. In case others are interested here is what the loadings print to... Loadings: Comp.1 Comp.2 Comp.3 Comp.4 Murder -0.536 0.418 -0.341 0.649 Assault -0.583 0.188 -0.268 -0.743 UrbanPop -0.278 -0.873 -0.378 0.134 Rape -0.543 -0.167 0.818 Comp.1 Comp.2 Comp.3 Comp.4 SS loadings 1.00 1.00 1.00 1.00 Proportion Var 0.25 0.25 0.25 0.25 Cumulative Var 0.25 0.50 0.75 1.00 Cheers, Ben > On Jan 29, 2017, at 4:31 AM, Fix Ace via R-help wrote: > > Hello, there, > I did a test run for this princomp() function using USArrests data. The R > document says that the output loadings contain the eigenvector matrix. When I > looked at this matrix, I found that a missing item for Comp.4 > >> p3=princomp(USArrests, cor=TRUE )> p3$loadings > Loadings: Comp.1 Comp.2 Comp.3 Comp.4Murder -0.536 0.418 -0.341 > 0.649Assault -0.583 0.188 -0.268 -0.743UrbanPop -0.278 -0.873 -0.378 > 0.134Rape -0.543 -0.167 0.818 > Comp.1 Comp.2 Comp.3 Comp.4SS loadings 1.00 1.00 1.00 >1.00Proportion Var 0.25 0.25 0.25 0.25Cumulative Var 0.25 0.50 0.75 >1.00 > How should I explain this? > Thanks. > Ace > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] get() return nothing
Hello, there, I wrote a loop to check the dimension of all the .txt dataframes:> ls() [1] "actualpca.table" "b4galnt2" "b4galnt2.txt" "data" [5] "galnt4" "galnt4.txt" "galnt5" "galnt5.txt" [9] "galnt6" "galnt6.txt" "glyco" "glyco.txt" [13] "i" "mtscaled" "newsig.table" "nicepca" [17] "pca" "sig.txt" "st3gal3" "st3gal3.txt" [21] "st3gal5" "st3gal5.txt" "st6gal1" "st6gal1.txt" > for(i in ls(pattern="txt")){dim(get(i))} > If I check individual ones, they are ok: > dim(get("galnt4.txt")) [1] 8 3 > could anyone help me to figure out why it did not work with a loop? Thanks a lot! Ace [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] get() return nothing
Well, I am not trying to print anything. I just would like to get the dimension information for all the dataframes I created. Could you please help me to develop the script? Thanks. Ace On Saturday, February 11, 2017 7:53 PM, Duncan Murdoch wrote: On 11/02/2017 1:33 PM, Fix Ace via R-help wrote: > Hello, there, > I wrote a loop to check the dimension of all the .txt dataframes:> ls() > [1] "actualpca.table" "b4galnt2" "b4galnt2.txt" "data" > [5] "galnt4" "galnt4.txt" "galnt5" "galnt5.txt" > [9] "galnt6" "galnt6.txt" "glyco" "glyco.txt" > [13] "i" "mtscaled" "newsig.table" "nicepca" > [17] "pca" "sig.txt" "st3gal3" "st3gal3.txt" > [21] "st3gal5" "st3gal5.txt" "st6gal1" "st6gal1.txt" >> for(i in ls(pattern="txt")){dim(get(i))} >> > If I check individual ones, they are ok: >> dim(get("galnt4.txt")) > [1] 8 3 >> > could anyone help me to figure out why it did not work with a loop? > Thanks a lot! It's the difference between for (i in 1:10) i (which prints nothing) and for (i in 1:10) print(i) Duncan Murdoch [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [FORGED] Re: get() return nothing
Thank you very much for the information! I will try it! Ace On Tuesday, February 14, 2017 8:48 AM, Ben Tupper wrote: Hi, When you want to get 'something' out of a loop you need to assign that 'something' to a variable that persists outside of the loop. I think it is a scoping thing. In your situation you could create a list with as many elements as there are objects with 'txt' in their names. I can't quite follow what is is you are after, but perhaps something like this (untested and I'm still on my first cup of coffee) ... obj_names <- ls(pattern="txt") obj_dims <- vector(mode = 'list', length = length(obj_names)) names(obj_dims) <- obj_names for (nm in obj_names)){ obj_dims[[nm]] <- dim(get(nm)) } Does that do what you want? If so, you could probably use lapply() for the purpose instead of the for loop, but even better is to store each of your objects in a list as you create them rather than letting them get loose in the global environment. That way you don't have to do this get-by-name rodeo to get info on them. Cheers, Ben > On Feb 14, 2017, at 2:57 AM, Rolf Turner wrote: > > > On 14/02/17 05:50, Fix Ace via R-help wrote: > >> Well, I am not trying to print anything. I just would like to get the >> dimension information for all the dataframes I created. Could you please >> help me to develop the script? >> Thanks. >> Ace > > Yes you *are* trying to print something. You are trying to print the > dimension information, i.e. dim(get(i))!!! For Pete's sake (a) *think* about > what you are doing and (b) *try* example that Duncan suggested to you. > > cheers, > > Rolf Turner >> >> On Saturday, February 11, 2017 7:53 PM, Duncan Murdoch >> wrote: >> >> >> On 11/02/2017 1:33 PM, Fix Ace via R-help wrote: >>> Hello, there, >>> I wrote a loop to check the dimension of all the .txt dataframes:> ls() >>> [1] "actualpca.table" "b4galnt2" "b4galnt2.txt" "data" >>> [5] "galnt4" "galnt4.txt" "galnt5" "galnt5.txt" >>> [9] "galnt6" "galnt6.txt" "glyco" "glyco.txt" >>> [13] "i" "mtscaled" "newsig.table" "nicepca" >>> [17] "pca" "sig.txt" "st3gal3" "st3gal3.txt" >>> [21] "st3gal5" "st3gal5.txt" "st6gal1" "st6gal1.txt" >>>> for(i in ls(pattern="txt")){dim(get(i))} >>>> >>> If I check individual ones, they are ok: >>>> dim(get("galnt4.txt")) >>> [1] 8 3 >>>> >>> could anyone help me to figure out why it did not work with a loop? >>> Thanks a lot! >> >> It's the difference between >> >> for (i in 1:10) i >> >> (which prints nothing) and >> >> for (i in 1:10) print(i) >> >> Duncan Murdoch >> >> >> >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > -- > Technical Editor ANZJS > Department of Statistics > University of Auckland > Phone: +64-9-373-7599 ext. 88276 > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.