Re: [R] function to filter identical data.fames using less than (<) and greater than (>)
My problem is that using "[" every time i want to extract my data of interest is cumbersome and verbose for the next guy suffering through reading my code. Since my extractions are always on the same columns and depend on either "<", ">" or neither, a wrapper function or perhaps different function besides "[" will likely solve my problem. Indeed Rui's example achieves exactly what i wanted. Keep in mind my grasp of R remains limited and you might think my problem is more complex than it is. So i'm only inviting further solution's to this problem for the sake of improving my grasp of R. You certainly have my understanding should this go beyond what you might invest your time in :) No less, your example code: eg$grpcol[with(eg,grpcol!="Default" & A<1 & B<1)] <- "ABTooLow") already provides educational material for me, thank you. Chrs, K On 06/12/12 18:00, Jeff Newmiller wrote: You ask me to provide code when you have only described your solution rather than your problem. That limits my options more than I care to allow for investing my time. When I think of problems that require repetitive subsetting I tend to look for solutions involving aggregation (?aggregate, ?plyr::ddply), which requires creating one or more grouping columns which can be formulated with the cut function or with logical indexed assignment (e.g. a sequence of statements something like eg$grpcol[with(eg,grpcol!="Default" & A<1 & B<1)] <- "ABTooLow"). So... what is your problem? --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Karl Brand wrote: Hi Jeff, Subset is indeed what's reuqired here. But using it every time it's needed was generating excessive amounts of obtuse code. So for the sake of clarity and convenience i wanted a wrapper function to replace these repetitious subsets. Although Rui's example works just fine, love to see any idiomatic ways you might attempt this (also for the sake of improving my grasp of R). Cheers, Karl On 06/12/12 15:57, Jeff Newmiller wrote: You have not indicated why the subset function is insufficient for your needs... --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Karl Brand wrote: Esteemed UseRs, I've got many biggish data frames which need a lot subsetting, like in this example: # example eg <- data.frame(A = rnorm(10), B = rnorm(10), C = rnorm(10), D = rnorm(10)) egsub <- eg[eg$A < 0 & eg$B < 1 & eg$C > 0, ] egsub egsub2 <- eg[eg$A > 1 & eg$B > 0, ] egsub2 # To make this clearer than 1000s of lines of extractions with [] # I tried to make a function like this: # func(data="eg", A="< 0", B="< 1", C="> 0") # Which would also need to be run as # func(data="eg", A="> 1", B="> 0", C=NA) #end Noteably: -the signs* "<" and ">" need to be flexible _and_ optional -the quantities also need to be flexible -column header names i.e, A, B and C don't need flexibility, i.e., can remain fixed * "less than" and "greater than" so google picks up this thread Once again i find just how limited my grasp of R is...Is do.call() the best way to call binary operators like < & > in a function? Is an ifelse statement needed for each column to make filtering on it optional? etc Any one with the patience to show their working version of such a funciton would receive my undying Rdulation. With thanks in advance, Karl -- Karl Brand Dept of Cardiology and Dept of Bioinformatics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 703 2460 |M +31 (0)642 777 268 |F +31 (0)10 704 4161 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] function to filter identical data.fames using less than (<) and greater than (>)
Hi Jeff, Subset is indeed what's reuqired here. But using it every time it's needed was generating excessive amounts of obtuse code. So for the sake of clarity and convenience i wanted a wrapper function to replace these repetitious subsets. Although Rui's example works just fine, love to see any idiomatic ways you might attempt this (also for the sake of improving my grasp of R). Cheers, Karl On 06/12/12 15:57, Jeff Newmiller wrote: You have not indicated why the subset function is insufficient for your needs... --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Karl Brand wrote: Esteemed UseRs, I've got many biggish data frames which need a lot subsetting, like in this example: # example eg <- data.frame(A = rnorm(10), B = rnorm(10), C = rnorm(10), D = rnorm(10)) egsub <- eg[eg$A < 0 & eg$B < 1 & eg$C > 0, ] egsub egsub2 <- eg[eg$A > 1 & eg$B > 0, ] egsub2 # To make this clearer than 1000s of lines of extractions with [] # I tried to make a function like this: # func(data="eg", A="< 0", B="< 1", C="> 0") # Which would also need to be run as # func(data="eg", A="> 1", B="> 0", C=NA) #end Noteably: -the signs* "<" and ">" need to be flexible _and_ optional -the quantities also need to be flexible -column header names i.e, A, B and C don't need flexibility, i.e., can remain fixed * "less than" and "greater than" so google picks up this thread Once again i find just how limited my grasp of R is...Is do.call() the best way to call binary operators like < & > in a function? Is an ifelse statement needed for each column to make filtering on it optional? etc Any one with the patience to show their working version of such a funciton would receive my undying Rdulation. With thanks in advance, Karl -- Karl Brand Dept of Cardiology and Dept of Bioinformatics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 703 2460 |M +31 (0)642 777 268 |F +31 (0)10 704 4161 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] function to filter identical data.fames using less than (<) and greater than (>)
Rui, Indeed it does help. Also very happy to see eval() and parse() employed and demystified here. In Rdulation, Karl On 06/12/12 15:48, Rui Barradas wrote: Hello, Something like this? func <- function(data, A, B, C){ f <- function(a) function(x) eval(parse(text = paste("x", a))) iA <- if(is.na(A)) TRUE else f(A)(data$A) iB <- if(is.na(B)) TRUE else f(B)(data$B) iC <- if(is.na(C)) TRUE else f(C)(data$C) data[iA & iB & iC, ] } func(eg, "> 0", NA, NA) func(data=eg, A="< 0", B="< 1", C="> 0") Hope this helps, Rui Barradas Em 06-12-2012 13:49, Karl Brand escreveu: Esteemed UseRs, I've got many biggish data frames which need a lot subsetting, like in this example: # example eg <- data.frame(A = rnorm(10), B = rnorm(10), C = rnorm(10), D = rnorm(10)) egsub <- eg[eg$A < 0 & eg$B < 1 & eg$C > 0, ] egsub egsub2 <- eg[eg$A > 1 & eg$B > 0, ] egsub2 # To make this clearer than 1000s of lines of extractions with [] # I tried to make a function like this: # func(data="eg", A="< 0", B="< 1", C="> 0") # Which would also need to be run as # func(data="eg", A="> 1", B="> 0", C=NA) #end Noteably: -the signs* "<" and ">" need to be flexible _and_ optional -the quantities also need to be flexible -column header names i.e, A, B and C don't need flexibility, i.e., can remain fixed * "less than" and "greater than" so google picks up this thread Once again i find just how limited my grasp of R is...Is do.call() the best way to call binary operators like < & > in a function? Is an ifelse statement needed for each column to make filtering on it optional? etc Any one with the patience to show their working version of such a funciton would receive my undying Rdulation. With thanks in advance, Karl -- Karl Brand Dept of Cardiology and Dept of Bioinformatics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 703 2460 |M +31 (0)642 777 268 |F +31 (0)10 704 4161 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] function to filter identical data.fames using less than (<) and greater than (>)
Esteemed UseRs, I've got many biggish data frames which need a lot subsetting, like in this example: # example eg <- data.frame(A = rnorm(10), B = rnorm(10), C = rnorm(10), D = rnorm(10)) egsub <- eg[eg$A < 0 & eg$B < 1 & eg$C > 0, ] egsub egsub2 <- eg[eg$A > 1 & eg$B > 0, ] egsub2 # To make this clearer than 1000s of lines of extractions with [] # I tried to make a function like this: # func(data="eg", A="< 0", B="< 1", C="> 0") # Which would also need to be run as # func(data="eg", A="> 1", B="> 0", C=NA) #end Noteably: -the signs* "<" and ">" need to be flexible _and_ optional -the quantities also need to be flexible -column header names i.e, A, B and C don't need flexibility, i.e., can remain fixed * "less than" and "greater than" so google picks up this thread Once again i find just how limited my grasp of R is...Is do.call() the best way to call binary operators like < & > in a function? Is an ifelse statement needed for each column to make filtering on it optional? etc Any one with the patience to show their working version of such a funciton would receive my undying Rdulation. With thanks in advance, Karl -- Karl Brand Dept of Cardiology and Dept of Bioinformatics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 703 2460 |M +31 (0)642 777 268 |F +31 (0)10 704 4161 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 deduplicate records, e.g. using melt() and cast()
Fantastic Jan, Thanks a lot for the example on how i achieve this with melt()/cast(). Very good for my understanding of these functions. Karl On 07/05/12 13:49, Jan van der Laan wrote: using reshape: library(reshape) m <- melt(my.df, id.var="pathway", na.rm=T) cast(m, pathway~variable, sum, fill=NA) Jan On 05/07/2012 12:30 PM, Karl Brand wrote: Dimitris, Petra, Thank you! aggregate() is my lesson for today, not melt() | cast() Really appreciate the super fast help, Karl On 07/05/12 12:09, Dimitris Rizopoulos wrote: you could try aggregate(), e.g., my.df <- data.frame(pathway = c(rep("pw.A", 2), rep("pw.B", 3), rep("pw.C", 1)), cond.one = c(0.5, NA, 0.4, NA, NA, NA), cond.two = c(NA, 0.6, NA, 0.9, NA, 0.2), cond.three = c(NA, NA, NA, NA, 0.1, NA)) aggregate(my.df[-1], my.df['pathway'], sum, na.rm = TRUE) or sum. <- function(x) if (all(is.na(x))) NA else sum(x, na.rm = TRUE) aggregate(my.df[-1], my.df['pathway'], sum.) I hope it helps. Best, Dimitris On 5/7/2012 11:50 AM, Karl Brand wrote: Esteemed UseRs, This must be embarrassingly trivial to achieve with e.g., melt() and cast(): deduplicating records ("pw.X" in example) for a given set of responses ("cond.Y" in example). Hopefully the runnable example shows clearly what i have and what i'm trying to convert it to. But i'm just not getting it, ?cast that is! So i'd really appreciate some ones patience to clarify this, using the reshape package, or any other approach. With sincere thanks in advance, Karl ## Runnable example ## The data.frame i have: library("reshape") my.df <- data.frame(pathway = c(rep("pw.A", 2), rep("pw.B", 3), rep("pw.C", 1)), cond.one = c(0.5, NA, 0.4, NA, NA, NA), cond.two = c(NA, 0.6, NA, 0.9, NA, 0.2), cond.three = c(NA, NA, NA, NA, 0.1, NA)) my.df ## The data fram i want: wanted.df <- data.frame(pathway = c("pw.A", "pw.B", "pw.C"), cond.one = c(0.5, 0.4, NA), cond.two = c(0.6, 0.9, 0.2), cond.three = c(NA, 0.1, NA)) wanted.df -- Karl Brand Dept of Cardiology and Dept of Bioinformatics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 703 2460 |M +31 (0)642 777 268 |F +31 (0)10 704 4161 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 deduplicate records, e.g. using melt() and cast()
Dimitris, Petra, Thank you! aggregate() is my lesson for today, not melt() | cast() Really appreciate the super fast help, Karl On 07/05/12 12:09, Dimitris Rizopoulos wrote: you could try aggregate(), e.g., my.df <- data.frame(pathway = c(rep("pw.A", 2), rep("pw.B", 3), rep("pw.C", 1)), cond.one = c(0.5, NA, 0.4, NA, NA, NA), cond.two = c(NA, 0.6, NA, 0.9, NA, 0.2), cond.three = c(NA, NA, NA, NA, 0.1, NA)) aggregate(my.df[-1], my.df['pathway'], sum, na.rm = TRUE) or sum. <- function(x) if (all(is.na(x))) NA else sum(x, na.rm = TRUE) aggregate(my.df[-1], my.df['pathway'], sum.) I hope it helps. Best, Dimitris On 5/7/2012 11:50 AM, Karl Brand wrote: Esteemed UseRs, This must be embarrassingly trivial to achieve with e.g., melt() and cast(): deduplicating records ("pw.X" in example) for a given set of responses ("cond.Y" in example). Hopefully the runnable example shows clearly what i have and what i'm trying to convert it to. But i'm just not getting it, ?cast that is! So i'd really appreciate some ones patience to clarify this, using the reshape package, or any other approach. With sincere thanks in advance, Karl ## Runnable example ## The data.frame i have: library("reshape") my.df <- data.frame(pathway = c(rep("pw.A", 2), rep("pw.B", 3), rep("pw.C", 1)), cond.one = c(0.5, NA, 0.4, NA, NA, NA), cond.two = c(NA, 0.6, NA, 0.9, NA, 0.2), cond.three = c(NA, NA, NA, NA, 0.1, NA)) my.df ## The data fram i want: wanted.df <- data.frame(pathway = c("pw.A", "pw.B", "pw.C"), cond.one = c(0.5, 0.4, NA), cond.two = c(0.6, 0.9, 0.2), cond.three = c(NA, 0.1, NA)) wanted.df -- Karl Brand Dept of Cardiology and Dept of Bioinformatics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 703 2460 |M +31 (0)642 777 268 |F +31 (0)10 704 4161 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 deduplicate records, e.g. using melt() and cast()
Esteemed UseRs, This must be embarrassingly trivial to achieve with e.g., melt() and cast(): deduplicating records ("pw.X" in example) for a given set of responses ("cond.Y" in example). Hopefully the runnable example shows clearly what i have and what i'm trying to convert it to. But i'm just not getting it, ?cast that is! So i'd really appreciate some ones patience to clarify this, using the reshape package, or any other approach. With sincere thanks in advance, Karl ## Runnable example ## The data.frame i have: library("reshape") my.df <- data.frame(pathway = c(rep("pw.A", 2), rep("pw.B", 3), rep("pw.C", 1)), cond.one = c(0.5, NA, 0.4, NA, NA, NA), cond.two = c(NA, 0.6, NA, 0.9, NA, 0.2), cond.three = c(NA, NA, NA, NA, 0.1, NA)) my.df ## The data fram i want: wanted.df <- data.frame(pathway = c("pw.A", "pw.B", "pw.C"), cond.one = c(0.5, 0.4, NA), cond.two = c(0.6, 0.9, 0.2), cond.three = c(NA, 0.1, NA)) wanted.df -- Karl Brand Dept of Cardiology and Dept of Bioinformatics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 703 2460 |M +31 (0)642 777 268 |F +31 (0)10 704 4161 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 updating package rJava (on ubuntu)
Simon, Thanks alot for the further clarification. As i said some where in my lengthy explanation - i don't what of the myriad steps were needed, only that they were performed and i now have an up-to-date rJava. Next time (actually coming up soon) i'll certainly be following the couple simple steps you suggest. Also good to know that Java 1.7 can be used with the latest R (which is all i intend to install). Thanks again for the follow up, Karl On 02/20/2012 03:37 AM, Simon Urbanek wrote: On Feb 19, 2012, at 4:31 PM, Karl Brand wrote: Hi Hasan, Success. For myself and FWIW to other useR's here's how i spent the sunny half of my sunday to achieve it :/ Many thanks for your and Simon's input, FWIW you should not need to set any custom settings if you system is properly configured (if you use Java 1.7 you may need R 2.14.0 or higher which works around some bugs in 1.7 binaries). On Debian/Ubuntu you just install your favorite JDK (Sun/Oracle or OpenJDK) and use 'sudo update-alternatives --config java' or 'sudo update-java-alternatives' (depending on the age of your system) to select the right one. The fact you you had to tweak PATH means that something is seriously broken or you did setup the alternatives configuration correctly. Cheers, Simon Karl Since: $ javac -version returned nothing i believe you (and Simon) were right, i.e, it (and JDK) were missing on my system. Furthermore: $ sudo R CMD javareconf Java interpreter : /usr/bin/java Java version : 1.6.0_23 Java home path : /usr/lib/jvm/java-6-openjdk/jre Java compiler: not present Java headers gen.: Java archive tool: Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm JNI cpp flags: Updating Java configuration in /etc/R Done. Some things are clearly absent i.e., Java compiler: not present Java headers gen.: Java archive tool: Now i have: $ javac -version javac 1.6.0_23 $ sudo R CMD javareconf Java interpreter : /usr/bin/java Java version : 1.6.0_23 Java home path : /usr/lib/jvm/java-6-openjdk/jre Java compiler: /usr/bin/javac Java headers gen.: /usr/bin/javah Java archive tool: /usr/bin/jar Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm JNI cpp flags: -I$(JAVA_HOME)/../include Updating Java configuration in /etc/R Done. Certainly i don't know exactly what was needed to achieve this. BUT - for posterities sake, this is what i did: ## purge and reinstall openjdk-6-jdk which turned outwasn't installed! ## how this can be when i have a /usr/lib/jvm/java-6-openjdk full of ## files i don't understand. Moreover since i had the previosu version ## of rJava running fine!!! $ sudo apt-get purge openjdk-6-jdk Package openjdk-6-jdk is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. ## install openjdk-6-jdk $ sudo apt-get install openjdk-6-jdk ## Per- http://ubuntuforums.org/showthread.php?t=1491846 ## added 2 entries to /etc/bash.bashrc file $ gksudo gedit /etc/bash.bashrc ## entries were: export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/jre export PATH=$PATH:$JAVA_HOME/bin ## note the addition of /jre for JAVA_HOME per- ## http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing $ source /etc/bash.bashrc ## confirmed $ echo $JAVA_HOME /usr/lib/jvm/java-6-openjdk/jre ## configured java $ sudo R CMD javareconf I was then able to update rJava in a new R-session. Also note that per- http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing $ apt-get install r-cran-rjava did NOT enable me to update my rJava. Unless i buggered up something else along the way :/ On 02/18/2012 10:20 PM, Hasan Diwan wrote: On 18 February 2012 13:13, Karl Brand wrote: Thanks for yout fast response. Thing is - i managed to get Version 0.9-1 installed and fully functional. And $ locate jdk returns too many entries to post here, so i'm pretty sure its on the machine. What you want to look for is javac, not jdk. On my ubuntu system, this is to be found at /usr/lib/jvm/java-6-openjdk-i386/bin/javac So i'd like to know how i can ensure it's "registered in R". This i have no idea how to do. I simply don't have enough R and linux experience. Also the thread i mentioned http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing seems to be about pointing R at t
Re: [R] help updating package rJava (on ubuntu)
Hi Hasan, Success. For myself and FWIW to other useR's here's how i spent the sunny half of my sunday to achieve it :/ Many thanks for your and Simon's input, Karl Since: $ javac -version returned nothing i believe you (and Simon) were right, i.e, it (and JDK) were missing on my system. Furthermore: $ sudo R CMD javareconf Java interpreter : /usr/bin/java Java version : 1.6.0_23 Java home path : /usr/lib/jvm/java-6-openjdk/jre Java compiler: not present Java headers gen.: Java archive tool: Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm JNI cpp flags: Updating Java configuration in /etc/R Done. Some things are clearly absent i.e., Java compiler: not present Java headers gen.: Java archive tool: Now i have: $ javac -version javac 1.6.0_23 $ sudo R CMD javareconf Java interpreter : /usr/bin/java Java version : 1.6.0_23 Java home path : /usr/lib/jvm/java-6-openjdk/jre Java compiler: /usr/bin/javac Java headers gen.: /usr/bin/javah Java archive tool: /usr/bin/jar Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm JNI cpp flags: -I$(JAVA_HOME)/../include Updating Java configuration in /etc/R Done. Certainly i don't know exactly what was needed to achieve this. BUT - for posterities sake, this is what i did: ## purge and reinstall openjdk-6-jdk which turned outwasn't installed! ## how this can be when i have a /usr/lib/jvm/java-6-openjdk full of ## files i don't understand. Moreover since i had the previosu version ## of rJava running fine!!! $ sudo apt-get purge openjdk-6-jdk Package openjdk-6-jdk is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. ## install openjdk-6-jdk $ sudo apt-get install openjdk-6-jdk ## Per- http://ubuntuforums.org/showthread.php?t=1491846 ## added 2 entries to /etc/bash.bashrc file $ gksudo gedit /etc/bash.bashrc ## entries were: export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/jre export PATH=$PATH:$JAVA_HOME/bin ## note the addition of /jre for JAVA_HOME per- ## http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing $ source /etc/bash.bashrc ## confirmed $ echo $JAVA_HOME /usr/lib/jvm/java-6-openjdk/jre ## configured java $ sudo R CMD javareconf I was then able to update rJava in a new R-session. Also note that per- http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing $ apt-get install r-cran-rjava did NOT enable me to update my rJava. Unless i buggered up something else along the way :/ On 02/18/2012 10:20 PM, Hasan Diwan wrote: On 18 February 2012 13:13, Karl Brand wrote: Thanks for yout fast response. Thing is - i managed to get Version 0.9-1 installed and fully functional. And $ locate jdk returns too many entries to post here, so i'm pretty sure its on the machine. What you want to look for is javac, not jdk. On my ubuntu system, this is to be found at /usr/lib/jvm/java-6-openjdk-i386/bin/javac So i'd like to know how i can ensure it's "registered in R". This i have no idea how to do. I simply don't have enough R and linux experience. Also the thread i mentioned http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing seems to be about pointing R at the right location of certain aspects of Java. But lacks enough explicit details for myself to be able use. A previous response indicated R javareconf -- this is the only configuration you should need. Let me know if you have further problems. -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3455 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 updating package rJava (on ubuntu)
Simon, Thanks for yout fast response. Thing is - i managed to get Version 0.9-1 installed and fully functional. And $ locate jdk returns too many entries to post here, so i'm pretty sure its on the machine. So i'd like to know how i can ensure it's "registered in R". This i have no idea how to do. I simply don't have enough R and linux experience. Also the thread i mentioned http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing seems to be about pointing R at the right location of certain aspects of Java. But lacks enough explicit details for myself to be able use. Thanks again, also for any further suggestions, Karl On 02/18/2012 07:45 PM, Simon Urbanek wrote: On Feb 18, 2012, at 10:44 AM, Karl Brand wrote: Esteemed useRs and Devs, Attempts to update package:rJava to the latest version have failed. See my code and output below. Notably, as suggested here http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing $ sudo apt-get install r-cran-rjava ran successfully without error or warning, but my rJava package is not updated, and remains un-updatable... Greatly appreciate any suggestions getting my rJava updated, Karl update.packages(lib.loc = "/usr/lib/R/site-library") --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done rJava : Version 0.9-1 installed in /usr/lib/R/site-library Version 0.9-3 available at http://cran.xl-mirror.nl Update (y/N/c)? y checking Java support in R... present: interpreter : '/usr/bin/java' archiver: '' compiler: '' header prep.: '' cpp flags : '' java libs : '-L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm' configure: error: Java Development Kit (JDK) is missing or not registered in R Make sure R is configured with full Java support (including JDK). Run R CMD javareconf as root to add Java support to R. ...so i do as suggested: $ sudo R CMD javareconf Java interpreter : /usr/bin/java Java version : 1.6.0_23 Java home path : /usr/lib/jvm/java-6-openjdk/jre Java compiler: not present Java headers gen.: Java archive tool: Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm JNI cpp flags: Updating Java configuration in /etc/R Done. But i still get the same error when trying to update rJava! Obviously - your'e lacking JDK on your machine - see the output above (you have only JRE, not JDK). If you want to compile rJava form sources you need to install JDK first, then add Java support to R (via javareconf) and then build rJava. Cheers, Simon sessionInfo() R version 2.14.1 (2011-12-22) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_AU.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_AU.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3455 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3455 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 updating package rJava (on ubuntu)
Esteemed useRs and Devs, Attempts to update package:rJava to the latest version have failed. See my code and output below. Notably, as suggested here http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing $ sudo apt-get install r-cran-rjava ran successfully without error or warning, but my rJava package is not updated, and remains un-updatable... Greatly appreciate any suggestions getting my rJava updated, Karl > update.packages(lib.loc = "/usr/lib/R/site-library") --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done rJava : Version 0.9-1 installed in /usr/lib/R/site-library Version 0.9-3 available at http://cran.xl-mirror.nl Update (y/N/c)? y checking Java support in R... present: interpreter : '/usr/bin/java' archiver: '' compiler: '' header prep.: '' cpp flags : '' java libs : '-L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm' configure: error: Java Development Kit (JDK) is missing or not registered in R Make sure R is configured with full Java support (including JDK). Run R CMD javareconf as root to add Java support to R. ...so i do as suggested: $ sudo R CMD javareconf Java interpreter : /usr/bin/java Java version : 1.6.0_23 Java home path : /usr/lib/jvm/java-6-openjdk/jre Java compiler: not present Java headers gen.: Java archive tool: Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm JNI cpp flags: Updating Java configuration in /etc/R Done. But i still get the same error when trying to update rJava! > sessionInfo() R version 2.14.1 (2011-12-22) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_AU.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_AU.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3455 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 does one start R within Emacs/ESS with root privileges?
Thanks a lot for sharing your experience and suggestions. I see now the logic of making use of my user library which doesn't require root privs. Apparently linux is actually set up to work well - something i'm not used to from the other OS i've used till now. And for the rare times i do need to install into the system-wide library, i think i'll survive in the terminal :P cheers, Karl On 2011-09-07 17:08, Spencer Graves wrote: Under Vista and Windows 7, I install R in a local directory "pgms" so I never have to worry about permissions. Under Linux, I use "su" not "sudo". Then I call R and install.packages. Then I quit R and "su" and continue with what I want. hope this helps. Spencer On 9/7/2011 5:11 AM, Karl Brand wrote: Cheers Paul. Its a very good point. Although i am curious how badly i can damage my R install by running as root. I always ran R in windows with admin. privileges without problems (touch wood). Probably best to never find out by sticking with user privileges. However, even for taking care of R install/maint. i'd prefer to do this interactively within Emacs rather than the terminal. Motivated by this, i'd still like to find out how to invoke R with root privileges. I've also reposted the original email on perhaps a more appropriate forum at: ess-h...@stat.math.ethz.ch Karl On 2011-09-07 11:02, Paul Hiemstra wrote: On 09/07/2011 08:54 AM, Karl Brand wrote: Esteemed UseRs and DevelopeRs, Apologies if this question belongs else where, but it does concern R's package installation/maintenance. How does one start R within Emacs/ESS with root privileges? I tried without success: M-x sudo R Why i'm motivated to do so: It seems logical to me, as the only user of the PC, to keep my R library consolidated in the universal library rather than splitting into universal and user libraries. Hence the desire to run R as root. Hi Karl, Why the need to install packages in root? As you are the only user there is not reason to install them system wide (to make them available to all users, which is just you). Installing the packages in your homedir solves your problem much easier, without the need to run R as root continuously. I think you should not run anything as root if it is not absolutely needed, which could potentially damage your system (accidentally overwriting something). hope this helps, Paul In addition, it's nice to be able to install packages 'on the fly' when and as needed and not need to launch a separate R session (as root) in the terminal just to install a package. Migrating from windows, i'm completey new to linux (ubuntu) and am seeing for myself if Emacs/ESS is as good as its purported to be. So maybe my motivation is nonsensical to expereinced ESS/R users. If so i'd really appreciate tips on efficient package installation/maintenance using Emacs/ESS. TIA, karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3455 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 does one start R within Emacs/ESS with root privileges?
Cheers Paul. Its a very good point. Although i am curious how badly i can damage my R install by running as root. I always ran R in windows with admin. privileges without problems (touch wood). Probably best to never find out by sticking with user privileges. However, even for taking care of R install/maint. i'd prefer to do this interactively within Emacs rather than the terminal. Motivated by this, i'd still like to find out how to invoke R with root privileges. I've also reposted the original email on perhaps a more appropriate forum at: ess-h...@stat.math.ethz.ch Karl On 2011-09-07 11:02, Paul Hiemstra wrote: On 09/07/2011 08:54 AM, Karl Brand wrote: Esteemed UseRs and DevelopeRs, Apologies if this question belongs else where, but it does concern R's package installation/maintenance. How does one start R within Emacs/ESS with root privileges? I tried without success: M-x sudo R Why i'm motivated to do so: It seems logical to me, as the only user of the PC, to keep my R library consolidated in the universal library rather than splitting into universal and user libraries. Hence the desire to run R as root. Hi Karl, Why the need to install packages in root? As you are the only user there is not reason to install them system wide (to make them available to all users, which is just you). Installing the packages in your homedir solves your problem much easier, without the need to run R as root continuously. I think you should not run anything as root if it is not absolutely needed, which could potentially damage your system (accidentally overwriting something). hope this helps, Paul In addition, it's nice to be able to install packages 'on the fly' when and as needed and not need to launch a separate R session (as root) in the terminal just to install a package. Migrating from windows, i'm completey new to linux (ubuntu) and am seeing for myself if Emacs/ESS is as good as its purported to be. So maybe my motivation is nonsensical to expereinced ESS/R users. If so i'd really appreciate tips on efficient package installation/maintenance using Emacs/ESS. TIA, karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3455 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 does one start R within Emacs/ESS with root privileges?
Esteemed UseRs and DevelopeRs, Apologies if this question belongs else where, but it does concern R's package installation/maintenance. How does one start R within Emacs/ESS with root privileges? I tried without success: > M-x sudo R Why i'm motivated to do so: It seems logical to me, as the only user of the PC, to keep my R library consolidated in the universal library rather than splitting into universal and user libraries. Hence the desire to run R as root. In addition, it's nice to be able to install packages 'on the fly' when and as needed and not need to launch a separate R session (as root) in the terminal just to install a package. Migrating from windows, i'm completey new to linux (ubuntu) and am seeing for myself if Emacs/ESS is as good as its purported to be. So maybe my motivation is nonsensical to expereinced ESS/R users. If so i'd really appreciate tips on efficient package installation/maintenance using Emacs/ESS. TIA, karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3455 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] X11 problem
Hi Carol, When i ran into this problem, using the instructions as guide from here: http://cran.r-project.org/bin/linux/ubuntu/ I did the following: Went to this site: http://keyserver.ubuntu.com:11371/ searched for: 0xE084DAB9 Then clicked the hyperlinked "E084DAB9", copy, pasted and saved as .txt the contents of the entire page that your served by this link. This 'key.txt' is then imported (via gui on 11.04 natty) by: synaptic > settings > repositories > authentification tab > click 'import key file' and select your saved 'key.txt' Hope it works for you, karl On 2011-08-25 15:41, carol white wrote: gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 gpg: requesting key E084DAB9 from hkp server keyserver.ubuntu.com gpgkeys: HTTP fetch error 7: couldn't connect to host gpg: no valid OpenPGP data found. gpg: Total number processed: 0 How to solve the problem? Cheers, Carol - Original Message - From: Alexander Engelhardt To: carol white Cc: "r-h...@stat.math.ethz.ch" Sent: Thursday, August 25, 2011 3:31 PM Subject: Re: [R] X11 problem Am 25.08.2011 15:05, schrieb carol white: both. But it worked for R-2-10. I added deb http://cran.ma.imperial.ac.uk/bin/linux/ubuntu lucid/ into /etc/apt/sources.list and ran apt-get update as root and got the following error message: W: GPG error: http://cran.ma.imperial.ac.uk lucid/ Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 51716619E084DAB9 W: GPG error: http://ppa.launchpad.net lucid Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B22AB97AF1CDFA9 Hey there, I had some problems with this just a few days ago. You need to import that GPG key. See the section "secure APT" here: http://cran.r-project.org/bin/linux/ubuntu/ Cheers, 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. -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3455 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] heatmap.2 - change column & row locations; angle / rotate
Hi Chakravarthy, [dont forget to Cc the list for useRs with the same Q.] If you're trying to reuduce the isze of your row or column labels, i think the following arguments of heatmap.2 {gplots} is what you want to adjust- 'cexCol' and 'cexRow'. Specifically on my question that you ask about, i found the BioC forum helpful: http://permalink.gmane.org/gmane.science.biology.informatics.conductor/30112 And in fact the phylotemp() function by default pretty much did exactly what i needed, available here: http://phylotemp.microeco.org/ However, it was pointed out to me that some times the best way to get it just right is using more basic functions, which for heatmaps would be image(). See: https://www.stat.math.ethz.ch/pipermail/bioconductor/2010-August/034995.html hth, karl On 04/18/2011 10:38 AM, chakri2...@yahoo.co.in wrote: Dear Karl Brand, I am facing same problem as you have faced before (see appended mail below). I am writing to you to find out whether you have found a solution ! I asked a similar question in R-forum (http://r.789695.n4.nabble.com/How-to-save-heatmap-as-image-or-pdf-td3412542.html#a3413871). Any pointers would be greatly appreciated Thanks Chakravarthy Junior Research Fellow Tata Institute of Fundamental Research Bangalore, India Esteemed R user's, I'm struggling to achieve some details of a heatmap using heatmap.2(): 1. Change label locations, for both rows& columns from the default right& bottom, to left and top. Can this be done within heatmap.2()? Or do i need to suppress this default behavior (how) and call a new function to relabel (what) specifying locations? 2. Change the angle of the labels. By default column labels are 90deg anti-clock-wise from horizontal. How to bring them back to horizontal? Or better, rotate 45deg clock-wise from horizontal (ie., rotate 135deg a.clock.wise from default)? Any suggestions or pointers to helpful resources greatly appreciated, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3455 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 corresponding to size in R
Hi Shira, Check out "venneuler" http://cran.r-project.org/web/packages/venneuler/index.html Labelling can be a little tricky, but if you search this forum for "venneuler" you'll find some tips which helped me. hth, karl On 03/09/2011 02:25 AM, Shira Rockowitz wrote: I was wondering if anyone could help me figure out how to make a Venn diagram in R where the circles are scaled to the size of each dataset. I have looked at the information for venn (in gplots) and vennDiagram (in limma) and I cannot seem to figure out what parameter to change. I have looked this up online and do not seem to be seeing anyone else who has posted this question or the answer to it before. I see graphs though that are purported to be made in R that are scaled like this, so I think it must be possible, although I do not know if they were made with a custom function. If I have just not been searching for this question correctly, and it has already been asked, please direct me to the earlier question. I would like to thank you all in advance for you help! ~Shira [[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. -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3455 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] attempted merge() returns: cannot coerce type 'closure' to vector of type 'any'
Cheers Bill, Thank you for the clarificaiton. Prabably showing the str() of these objects would have made it easier for you see exatly where i was going wrong. Which as David pointed out, was really a lack of ?merge reading...:) Karl On 12/2/2010 5:46 PM, William Dunlap wrote: I didn't change your "rownames" to "row.names" because I figured you had the name you wanted but only forgot to include the quotes. Both "rownames" and "row.names" are valid inputs, but they mean different things. Howver, without the quotes you were passing in the contents of the object called rownames, which happens to be a function (aka a closure), not the string "rownames. The quotes are needed to distinguish between things and names of things. Some functions (e.g., library() and help()) try to cover up this difference, leading to occasional difficulties using them. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: Karl Brand [mailto:k.br...@erasmusmc.nl] Sent: Thursday, December 02, 2010 2:22 AM To: William Dunlap Cc: r-help@r-project.org; Dimitris Rizopoulos Subject: Re: [R] attempted merge() returns: cannot coerce type 'closure' to vector of type 'any' Cheers Bill. You got me halfway, since: > temp<- merge(x=x, y=y[,17, drop=FALSE], by="rownames", sort=FALSE) Error in fix.by(by.x, x) : 'by' must specify valid column(s) but, using "row.names" instead of "rownames", like: > temp<- merge(x=x, y=y[,17, drop=FALSE], by="row.names", sort=FALSE) works (but adds a column "Row.names"). Which seems some what counter intuitive to me since i am feeding in two matrices to the merge function, which i understand have 'rownames', not 'row.names' as data frames have, right? Although the output of merge() is a data frame... thanks again, Karl On 12/1/2010 6:08 PM, William Dunlap wrote: Try by="rownames" instead of by=rownames Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Karl Brand Sent: Wednesday, December 01, 2010 6:35 AM To: Dimitris Rizopoulos Cc: r-help@r-project.org Subject: [R] attempted merge() returns: cannot coerce type 'closure' to vector of type 'any' Hi Dimtris and esteemed useRs, I don't understand why i get this error message when attempting to use merge() - > temp<- merge(x, y[,17, drop=FALSE], by=rownames, sort=FALSE) Error in as.vector(x, mode) : cannot coerce type 'closure' to vector of type 'any' It should work because: > all(rownames(x[order(rownames(x)),]) == + rownames(y[order(rownames(y[,17, drop=FALSE])),17, drop=FALSE]) [TRUNCATED] [1] TRUE also: > class(x); class(y[,17, drop=FALSE]) [1] "matrix" [1] "matrix" Any idea why i cant use merge() in the normal way here? I'm forced to add the column using: temp.b<- cbind(x, y[match(rownames(x), rownames(y)),17]) All insights appreciated for this leaRner, cheers, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3211 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 ______ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3211 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3211 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] attempted merge() returns: cannot coerce type 'closure' to vector of type 'any'
On 12/2/2010 3:52 PM, David Winsemius wrote: On Dec 2, 2010, at 5:58 AM, Karl Brand wrote: On 12/2/2010 11:36 AM, David Winsemius wrote: On Dec 2, 2010, at 5:22 AM, Karl Brand wrote: Cheers Bill. Inserting earlier debris: I don't understand why i get this error message when attempting to use merge() - > temp <- merge(x, y[,17, drop=FALSE], by=rownames, sort=FALSE) Error in as.vector(x, mode) : cannot coerce type 'closure' to vector of type 'any' Try by="rownames" instead of by=rownames At this point I think Bill should have suggested by="row.names" since that is the correct argument to merge() when asking for a rownames match, and you appear to have found that by experimentation since you didn't seem to have read the help page. You got me halfway, since: > temp <- merge(x=x, y=y[,17, drop=FALSE], by="rownames", sort=FALSE) Error in fix.by(by.x, x) : 'by' must specify valid column(s) but, using "row.names" instead of "rownames", like: > temp <- merge(x=x, y=y[,17, drop=FALSE], by="row.names", sort=FALSE) works (but adds a column "Row.names"). OK. It added a column what's the problem? The help(merge) pages says: "If the matching involved row names, an extra character column called Row.names is added at the left, and in all cases the result has ‘automatic’ row names." Which seems some what counter intuitive to me since i am feeding in two matrices to the merge function, which i understand have 'rownames', not 'row.names' as data frames have, right? Although the output of merge() is a data frame... Right. The merge function takes either dataframes or things which can be coerced to dataframes as arguments and returns a dataframe. That is exactly what the help(merge) page states outright (in many places). Just because your arguments were matrices doesn't mean the returned object should be one. Had you wanted it to be an "augmented" data.matrix with rownames as before, you could gotten that after merge by: ?data.matrix temp2 <- datamatrix(temp[-1]) rownames(temp2) <- temp$Row.names (Or by the rather nice manipulations that you described using rownames as indices.) I think I understand the "problem" now that you were expecting merge() to behave differently than is documented. Cheers David, You nailed it- closer attention to the help page would defiently have saved us time. No less, thanks a lot for highlighting this, and also for the merge() clarifications. And insight into what physicists have to deaal with :) cheers, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3211 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] attempted merge() returns: cannot coerce type 'closure' to vector of type 'any'
On 12/2/2010 11:36 AM, David Winsemius wrote: On Dec 2, 2010, at 5:22 AM, Karl Brand wrote: Cheers Bill. You got me halfway, since: > temp <- merge(x=x, y=y[,17, drop=FALSE], by="rownames", sort=FALSE) Error in fix.by(by.x, x) : 'by' must specify valid column(s) but, using "row.names" instead of "rownames", like: > temp <- merge(x=x, y=y[,17, drop=FALSE], by="row.names", sort=FALSE) works (but adds a column "Row.names"). Which seems some what counter intuitive to me since i am feeding in two matrices to the merge function, which i understand have 'rownames', not 'row.names' as data frames have, right? Although the output of merge() is a data frame... This reminds me of physicists using high energy particles to investigate the structure of the nucleus. But you have alternatives to what might be called "destructive debugging through binoculars". Instead of throwing code at your data and asking the assembled audience of soothsayers to tell you what went wrong by examining the debris, why don't you show us what the data objects actually look like? Ofcourse David, sorry- my lazy. Is str() enough to put away the binoculuars and maybe highlight the source of my ignorance? > str(x) num [1:140, 1:7] 4.93e-02 2.83e-02 1.07e-02 2.68e-02 3.92e-05 ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:140] "1415743_at" "1415887_at" "1416332_at" "1416340_a_at" ... ..$ : chr [1:7] "R.S.adj.pvalue" "R.S.Tau" "R.S.xpiek" "R.S.xdal" ... > str(y) num [1:140, 1:18] 0.573 1 0.752 0.768 0.399 ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:140] "1427982_s_at" "1430520_at" "1454086_a_at" "1419652_s_at" ... ..$ : chr [1:18] "R.S.1" "R.S.2" "R.S.3" "R.S.4" ... > source(.trPaths[5], echo=TRUE, max.deparse.length=150) > str(temp) 'data.frame': 140 obs. of 9 variables: $ Row.names :Class 'AsIs' chr [1:140] "1415743_at" "1415887_at" "1416332_at" "1416340_a_at" ... $ R.S.adj.pvalue: num 4.93e-02 2.83e-02 1.07e-02 2.68e-02 3.92e-05 ... $ R.S.Tau : num 21.6 23.6 26.6 29.7 18.8 20 24.6 27.9 23.9 22.7 ... $ R.S.xpiek : num 6.74 17.46 15.81 15.39 14.73 ... $ R.S.xdal : num 16.94 1.76 22.8 1.12 5.41 ... $ R.S.p1: num 0.0004 0.0001 0.0467 0.0024 0 ... $ R.S.p2: num 0.0039 0 0.002 0.019 0.0001 0.0035 0.0351 0.0126 0.0028 0.0192 ... $ R.S.p3: num 0.0178 0.0004 0.0101 0.0312 0.0012 0.022 0.0008 0.0151 0.0048 0.0317 ... $ V1: num 3.96 -0.94 1.04 1.94 -2.53 ... > -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3211 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] attempted merge() returns: cannot coerce type 'closure' to vector of type 'any'
Cheers Bill. You got me halfway, since: > temp <- merge(x=x, y=y[,17, drop=FALSE], by="rownames", sort=FALSE) Error in fix.by(by.x, x) : 'by' must specify valid column(s) but, using "row.names" instead of "rownames", like: > temp <- merge(x=x, y=y[,17, drop=FALSE], by="row.names", sort=FALSE) works (but adds a column "Row.names"). Which seems some what counter intuitive to me since i am feeding in two matrices to the merge function, which i understand have 'rownames', not 'row.names' as data frames have, right? Although the output of merge() is a data frame... thanks again, Karl On 12/1/2010 6:08 PM, William Dunlap wrote: Try by="rownames" instead of by=rownames Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Karl Brand Sent: Wednesday, December 01, 2010 6:35 AM To: Dimitris Rizopoulos Cc: r-help@r-project.org Subject: [R] attempted merge() returns: cannot coerce type 'closure' to vector of type 'any' Hi Dimtris and esteemed useRs, I don't understand why i get this error message when attempting to use merge() - > temp<- merge(x, y[,17, drop=FALSE], by=rownames, sort=FALSE) Error in as.vector(x, mode) : cannot coerce type 'closure' to vector of type 'any' It should work because: > all(rownames(x[order(rownames(x)),]) == + rownames(y[order(rownames(y[,17, drop=FALSE])),17, drop=FALSE]) [TRUNCATED] [1] TRUE also: > class(x); class(y[,17, drop=FALSE]) [1] "matrix" [1] "matrix" Any idea why i cant use merge() in the normal way here? I'm forced to add the column using: temp.b<- cbind(x, y[match(rownames(x), rownames(y)),17]) All insights appreciated for this leaRner, cheers, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3211 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3211 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] attempted merge() returns: cannot coerce type 'closure' to vector of type 'any'
Hi Dimtris and esteemed useRs, I don't understand why i get this error message when attempting to use merge() - > temp <- merge(x, y[,17, drop=FALSE], by=rownames, sort=FALSE) Error in as.vector(x, mode) : cannot coerce type 'closure' to vector of type 'any' It should work because: > all(rownames(x[order(rownames(x)),]) == + rownames(y[order(rownames(y[,17, drop=FALSE])),17, drop=FALSE]) [TRUNCATED] [1] TRUE also: > class(x); class(y[,17, drop=FALSE]) [1] "matrix" [1] "matrix" Any idea why i cant use merge() in the normal way here? I'm forced to add the column using: temp.b <- cbind(x, y[match(rownames(x), rownames(y)),17]) All insights appreciated for this leaRner, cheers, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3211 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] venneuler (java?) color palette 0 - 1
Hi Paul, That's pretty much awesome. Thank you very much. And combined with the colorspace package functions- rainbow_hcl() and sequential_hcl() -make color selection easy. One thing i was digging for was a function that yields a color palette *and* the hcl() call needed to produce it. This would help me better understand the hcl format. So where i can get the RGB codes like this- > rainbow_hcl(4) [1] "#E495A5" "#ABB065" "#39BEB1" "#ACA4E2" > - which is fine for color specification, is there a palette function that might help obtain the hcl() call needed to produce a given palette? ie., the 'h', 'c' and 'l' (and 'alpha' if appropriate) values for a given color/shade?? Thanks again and in advance for any further pointers, Karl On 10/10/2010 10:41 PM, Paul Murrell wrote: Hi On 11/10/2010 9:01 a.m., Karl Brand wrote: Dear UseRs and DevelopeRs It would be helpful to see the color palette available in the venneuler() function. The relevant par of ?venneuler states: "colors: colors of the circles as values between 0 and 1" -which explains color specification, but from what pallette? Short of trial and error, i'd really appreciate if some one could help me locate a "0 - 1" pallette for this function to aid with color selection. The color spec stored in the VennDiagram object is multiplied by 360 to give the "hue" component of an hcl() colour specification. For example, 0.5 would mean the colour hcl(0.5*360, 130, 60) Alternatively, you can control the colours when you call plot, for example, ... plot(ve, col=c("red", "green", "blue")) ... should work. Paul FWIW, i tried the below code and received the displayed error. I failed to turn up any solutions to this error... Any suggestions appreciated, Karl library(venneuler) ve<- venneuler(c("A"=1, "B"=2, "C"=3, "A&C"=0.5, "A&B&C"=0.1)) class(ve) [1] "VennDiagram" ve$colors<- c("red", "green", "blue") plot(ve) Error in col * 360 : non-numeric argument to binary operator -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] venneuler (java?) color palette 0 - 1
Dear UseRs and DevelopeRs It would be helpful to see the color palette available in the venneuler() function. The relevant par of ?venneuler states: "colors: colors of the circles as values between 0 and 1" -which explains color specification, but from what pallette? Short of trial and error, i'd really appreciate if some one could help me locate a "0 - 1" pallette for this function to aid with color selection. FWIW, i tried the below code and received the displayed error. I failed to turn up any solutions to this error... Any suggestions appreciated, Karl library(venneuler) ve <- venneuler(c("A"=1, "B"=2, "C"=3, "A&C"=0.5, "A&B&C"=0.1)) class(ve) [1] "VennDiagram" ve$colors <- c("red", "green", "blue") plot(ve) Error in col * 360 : non-numeric argument to binary operator -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] venneuler() - customize a few things.
Cheers Ista, I thought 'labels' and 'colors' must have been accessible some how. Thank you very much for showing how to access them, Karl On 10/7/2010 7:26 PM, Ista Zahn wrote: Hi Kari, On Thu, Oct 7, 2010 at 12:05 PM, Karl Brand wrote: Esteemed UseRs and DevelopeRs, Just coming to terms with the very attractive proportional venn gernator, venneuler(), but would like to customize a few things. Is it possible to- Say v is a VennDiagram: -suppress all circle labels? v$labels<- rep("", length(v$labels) -suppress only certain circle labels? v$labels<- c("A", "", "C") ## don't print label for B -print specific text strings at specified locations within the circles? and unions? text(.5, .5, "my text here") will print "my text here" right in the middle of the graph. Adjusting the coordinates will adjust the location. You can use v$centers and v$diameters to position text relative to the center of the circles, but I'm not sure how to automatically find the unions. You could do it by trial and error. -specify circle colors? v$colors<- c(.1, .5, .9) -specify label font, size& color? see ?text Best, Ista All thoughts and response's greatly appreciated, cheers, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] venneuler() - customize a few things.
Esteemed UseRs and DevelopeRs, Just coming to terms with the very attractive proportional venn gernator, venneuler(), but would like to customize a few things. Is it possible to- -suppress all circle labels? -suppress only certain circle labels? -print specific text strings at specified locations within the circles? and unions? -specify circle colors? -specify label font, size & color? All thoughts and response's greatly appreciated, cheers, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] create a '3D line plot'
Cheers! All excellent, runable examples helping me progress quickly. Being more a qualitative plot, the y-axis is less important. But it did get me thinking- Coloring each of the plotted lines, say 'altitude colors' like the classic volcano example to reflect the (scaled) values the lines represent might be effective at representing individual y-axis magnitude for each line. Perhaps gray background at least. Maybe if there were examples of the lines() func. using colors dependent on the y-value? Or some one already made a function for achieving this? (Google didnt return anything obvious for me...yet). Sincere thanks for help thus far, and welcome any further pointers, Karl On 9/12/2010 4:50 PM, Duncan Murdoch wrote: On 12/09/2010 10:12 AM, Karl Brand wrote: Esteemed useRs and developeRs, I need to create a '3D line plot' (proper name?) of which an excellent example can be viewed here: http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg I have some experience using the rgl package to create 3D PCA plots, but have no idea where to start for an image like this. I'd really appreciate suggestions & help on how might achieve this using R, I wouldn't use rgl for that: it's really a flat 2D plot, without perspective, shading or anything else that 3D plots have other than foreground objects hiding background ones. You can draw it by using polygon() to hide the background then lines() to draw the lines. Here's an example using regular 2d graphics: n <- 60 m <- 50 x <- seq(-4,4, len=m) # Make up some fake y data y <- matrix(NA, n, m) for (i in 1:n) y[i,] <- dnorm(x)*runif(m, 0.5,1) par(bg="black") yrange <- range(c(y, y+n/20)) plot(x, x, type="n", axes=FALSE, bg="black", ylim=yrange) for (i in n:1) { y1 <- c(y[i,] + i/20, 0, 0) x1 <- c(x, x[m], x[1]) polygon(x1,y1,col="black") lines(x, y[i,] + i/20, col="white") } The problem with this kind of plot is that it's almost impossible to display a usable vertical scale. Duncan Murdoch -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] create a '3D line plot'
Esteemed useRs and developeRs, I need to create a '3D line plot' (proper name?) of which an excellent example can be viewed here: http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg I have some experience using the rgl package to create 3D PCA plots, but have no idea where to start for an image like this. I'd really appreciate suggestions & help on how might achieve this using R, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 'programatically' list or call objects for use in a function?
Cheers Duncan, for your FAST answers and patience. (fast patience?!) I was close. But closer reading of ?save would also have worked i see now :$. LETTERS[] = :) thanks again, Karl On 9/11/2010 2:10 PM, Duncan Murdoch wrote: On 11/09/2010 8:00 AM, Karl Brand wrote: Esteemed R users and developers, How does one 'programatically' list or call objects for use in a function? It depends on the function. For example, i thought i could do something better than this: save(A.cwb, B.cwb, C.cwb, D.cwb, E.cwb, F.cwb, file="afile.RData") with something like these- prfxs <- c("A", "B", "C", "D", "E", "F") #** save(as.name(paste(prfxs, "cwb", sep=".")), file="afile.RData") For save, use list=paste(prfxs, "cwb", sep="."). or this- do.call(save, paste(prfxs, "cwb", sep="."), file="afile.RData") do.call wants a *list* of arguments, not a single vector of character strings. You could construct a list of the names of the objects you want to save, but that's a pain. Just use the list= argument (which doesn't want a list argument :-). Both failed. #** And while i've got your attention- is there a 'letter equivalent' to seq() which would have worked nicely for prfxs? ie., letter.seq(A:F) Not that I know of, but LETTERS[1:6] will give you the sequence, and it's easy to write a function that you'd call as letter.seq("A", "F"). Having your function work as in your example would be messy. Duncan Murdoch Thoughts and suggestions sincerely appreciated, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 'programatically' list or call objects for use in a function?
Esteemed R users and developers, How does one 'programatically' list or call objects for use in a function? For example, i thought i could do something better than this: save(A.cwb, B.cwb, C.cwb, D.cwb, E.cwb, F.cwb, file="afile.RData") with something like these- prfxs <- c("A", "B", "C", "D", "E", "F") #** save(as.name(paste(prfxs, "cwb", sep=".")), file="afile.RData") or this- do.call(save, paste(prfxs, "cwb", sep="."), file="afile.RData") Both failed. #** And while i've got your attention- is there a 'letter equivalent' to seq() which would have worked nicely for prfxs? ie., letter.seq(A:F) Thoughts and suggestions sincerely appreciated, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 do I transform this to a for loop
I think i've got it: for() is best employed for convenience only; and best NOT employed in computation for which many other approaches/functions are better suited (faster). Many thanks for your comment, Karl On 9/7/2010 12:52 AM, bill.venab...@csiro.au wrote: I have in mind the following quote from John Chambers Tradition among experienced S programmers has always been that loops (typically 'for' loops) are intrinsically inefficient: expressing computations without loops has provided a measure of entry into the inner circle of S programming. -- John Chambers Programming With Data, p. 173 (1998) If I had to do a series of computations like this I would actually use the loop to create the code and then run it as a batch job. Loops can be very slow because of 'backout'. Try the following little script, which take about no time at all. comm<- quote(M<- arima(data.ts[START:FINISH], order = c(1,1,1))) subst<- function(Command, ...) do.call("substitute", list(Command, list(...))) sink("fitArmias.R") for(i in 1:100) { thisComm<- subst(comm, M = as.name(paste("arima", substring(1000+i, 2), sep = "")), START = 0+i, FINISH = 200+i) print(thisComm) } sink() and then look at the file fitArimas.R. If you were to run this as a batch job - the way I would do things - it would work *much* faster than doing the same thing in a for() loop the way I suggested. Just a comment, of course. Bill Venables. -Original Message- From: Karl Brand [mailto:k.br...@erasmusmc.nl] Sent: Monday, 6 September 2010 6:46 PM To: Venables, Bill (CMIS, Cleveland) Cc: gaut...@yahoo.com; r-help@r-project.org Subject: Re: [R] how do I transform this to a for loop Hi Bill, I didn't make the original post, but its pretty similar to some thing i would have queried the list about. But, as an R dilatante i find more curious your question- "...but why would you want to do so?" Is this because you'd typically use the given nine lines of explicit code to carve up a single dataset into nine symmetrical variants ? Or that some contextual information may affect how you would write the for() loop? As i lack the experience to know any better, i perceive your for() loop as de rigour in efficient use of R, and the preferance of all experienced R user's. But not having any formal education in R or role models as such, its only an assumption (compeletely ignoring for the moment processing efficiency/speed, rounding error and such). But which i now question! Explicit, simple crude looking code; or, something which demands a little more proficiency with the language? cheers, Karl On 9/6/2010 6:16 AM, bill.venab...@csiro.au wrote: sseq<- c(1, seq(5, 40, by = 5)) for(i in 1:length(sseq)) assign(paste("arima", i, sep=""), arima(data.ts[sseq[i]:(sseq[i]+200)], order=c(1,1,1))) ...but why would you want to do so? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of lord12 Sent: Monday, 6 September 2010 10:57 AM To: r-help@r-project.org Subject: [R] how do I transform this to a for loop arima1<- arima(data.ts[1:201], order = c(1,1,1)) arima2<- arima(data.ts[5:205], order = c(1,1,1)) arima3<- arima(data.ts[10:210], order = c(1,1,1)) arima4<- arima(data.ts[15:215], order = c(1,1,1)) arima5<- arima(data.ts[20:220], order = c(1,1,1)) arima6<- arima(data.ts[25:225], order = c(1,1,1)) arima7<- arima(data.ts[30:230], order = c(1,1,1)) arima8<- arima(data.ts[35:235], order = c(1,1,1)) arima9<- arima(data.ts[40:240], order = c(1,1,1)) -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 do I transform this to a for loop
Hi Paul, Ivan, Hartstikke bedankt and thanks alot for sharing these thoughts. I can see 'listing up' multiple symmetrical data sets makes a lot of sense. As does using lapply() on them which i understand to be more efficient/faster than for(). Goodo- with your concensus (and helpful examples) i can tell myself investing the extra time to use lapply on lists /will/ pay off in the long run vs. copying and pasting (nearly) the same line of code 10 times for every data manipulation... thanks again, Karl On 9/6/2010 12:09 PM, Paul Hiemstra wrote: Hi Karl, The "why do it like this" is probably direct towards creating 9 new objects for the arima results (Is this right Bill?). A better option would be to create a list with nine entries. This is much easier for any subsequent analyses. An example that uses lapply (an efficient syntax for loops): sseq <- c(1, seq(5, 40, by = 5)) result_list = lapply(sseq, function(num) { arima(data.ts[num:(num+200)], order=c(1,1,1)) }) cheers, Paul On 09/06/2010 10:46 AM, Karl Brand wrote: Hi Bill, I didn't make the original post, but its pretty similar to some thing i would have queried the list about. But, as an R dilatante i find more curious your question- "...but why would you want to do so?" Is this because you'd typically use the given nine lines of explicit code to carve up a single dataset into nine symmetrical variants ? Or that some contextual information may affect how you would write the for() loop? As i lack the experience to know any better, i perceive your for() loop as de rigour in efficient use of R, and the preferance of all experienced R user's. But not having any formal education in R or role models as such, its only an assumption (compeletely ignoring for the moment processing efficiency/speed, rounding error and such). But which i now question! Explicit, simple crude looking code; or, something which demands a little more proficiency with the language? cheers, Karl On 9/6/2010 6:16 AM, bill.venab...@csiro.au wrote: sseq<- c(1, seq(5, 40, by = 5)) for(i in 1:length(sseq)) assign(paste("arima", i, sep=""), arima(data.ts[sseq[i]:(sseq[i]+200)], order=c(1,1,1))) ...but why would you want to do so? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of lord12 Sent: Monday, 6 September 2010 10:57 AM To: r-help@r-project.org Subject: [R] how do I transform this to a for loop arima1<- arima(data.ts[1:201], order = c(1,1,1)) arima2<- arima(data.ts[5:205], order = c(1,1,1)) arima3<- arima(data.ts[10:210], order = c(1,1,1)) arima4<- arima(data.ts[15:215], order = c(1,1,1)) arima5<- arima(data.ts[20:220], order = c(1,1,1)) arima6<- arima(data.ts[25:225], order = c(1,1,1)) arima7<- arima(data.ts[30:230], order = c(1,1,1)) arima8<- arima(data.ts[35:235], order = c(1,1,1)) arima9<- arima(data.ts[40:240], order = c(1,1,1)) -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 do I transform this to a for loop
Hi Bill, I didn't make the original post, but its pretty similar to some thing i would have queried the list about. But, as an R dilatante i find more curious your question- "...but why would you want to do so?" Is this because you'd typically use the given nine lines of explicit code to carve up a single dataset into nine symmetrical variants ? Or that some contextual information may affect how you would write the for() loop? As i lack the experience to know any better, i perceive your for() loop as de rigour in efficient use of R, and the preferance of all experienced R user's. But not having any formal education in R or role models as such, its only an assumption (compeletely ignoring for the moment processing efficiency/speed, rounding error and such). But which i now question! Explicit, simple crude looking code; or, something which demands a little more proficiency with the language? cheers, Karl On 9/6/2010 6:16 AM, bill.venab...@csiro.au wrote: sseq<- c(1, seq(5, 40, by = 5)) for(i in 1:length(sseq)) assign(paste("arima", i, sep=""), arima(data.ts[sseq[i]:(sseq[i]+200)], order=c(1,1,1))) ...but why would you want to do so? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of lord12 Sent: Monday, 6 September 2010 10:57 AM To: r-help@r-project.org Subject: [R] how do I transform this to a for loop arima1<- arima(data.ts[1:201], order = c(1,1,1)) arima2<- arima(data.ts[5:205], order = c(1,1,1)) arima3<- arima(data.ts[10:210], order = c(1,1,1)) arima4<- arima(data.ts[15:215], order = c(1,1,1)) arima5<- arima(data.ts[20:220], order = c(1,1,1)) arima6<- arima(data.ts[25:225], order = c(1,1,1)) arima7<- arima(data.ts[30:230], order = c(1,1,1)) arima8<- arima(data.ts[35:235], order = c(1,1,1)) arima9<- arima(data.ts[40:240], order = c(1,1,1)) -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 remove all objects except a few specified objects?
Hi Cheng, Check out the keep() function in package:gdata. And to be sure the "removed" objects are really removed from system memory i think you need to run gc(). hth, Karl On 8/23/2010 9:00 PM, Cheng Peng wrote: How to remove all R objects in the RAM except for a few specified ones? rm(list=ls()) removes all R objects in the R work space. Another question is that whether removing all R objects actually releases the RAM? Thanks. -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 set chart output size in rgl (surface3d)?
Hi Mandy and esteemed R users, I'm searching for the functions you used to produce the shaded bounding box (and axis for that matter) of the plot image* attached to your orginal post. Would you or anyone else be patient enough to post an example of such code or point me to the relevant functions? I think my PCA would certainly appear a lot more '3d' with such a shaded box & axis. tia, Karl * http://tolstoy.newcastle.edu.au/R/e10/help/att-3419/vol_surface.png -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] heatmap.2() yielding an inappropriate key?
I see now my error, several in fact: The 'breaks' specified need to be of a similar range to the data range, and they should be equally spaced. So in my example: breaks = seq(0, 0.2, 0.001) If one needs uneqaully spaced coloring, as i do, then this is achieved by specifying the approprate color per bin, and repeating the same color as needed. Script below achives my goal. But if anyone has a simpler method they'd care to share- would be v. happy to receive! karl #achives my goal library(gplots) BRKS <- seq(0, 0.2, 0.001) COLS <- c(rep(heat.colors(4)[1], 10), # 0.00-0.01 bin (10 bins) rep(heat.colors(4)[2], 40), # 0.01-0.05 'bin' (40 bins) rep(heat.colors(4)[3], 25), # 0.05-0.075 'bin' (25 bins) rep(heat.colors(4)[4], 25), # 0.075-0.1 'bin' (25 bins) rep("gray", (length(BRKS)-100)-1))# 0.10-1.0 'bin' (100 bins) set.seed(5) mat <- matrix(runif(50, min=0, max=0.2), nrow = 10, ncol = 5) heatmap.2(mat, Rowv=NULL, Colv=NULL, col = COLS, breaks = BRKS, trace = "none", dendrogram = "none", density.info = "none", margins=c(12, 8)) On 7/19/2010 12:42 PM, Karl Brand wrote: Esteemed R-users, heatmap.2() is yielding an inappropriate key based on my colors and break-points. In the reproducible example below, the key is inappropriate (to me) because- 1. 'Orange' is simply not represented in the key, despite its prescence in the heatmap. 2. The proportions of the key are clearly out, ie., my largest bin, (0.1 - 0.2) is half the range, but this bin (colored "gray") clearly extnds bellow the "0.1" tick mark of the key, beyond its specified bin. What am i missing/doing wrong? Or for a key set up like this example is heatmap.2() unsuitable, necessitating production with another graphics functions? If so, recommendations appreciated. I have tried ggplot2, but struggle getting this function producing what i need. And i just need to make a nice key at this point. All thoughts and suggestions greatly appreciated. cheers, karl #reproducible example: library(gplots) set.seed(5) mat <- matrix(runif(50, min=0, max=0.2), nrow = 10, ncol = 5) heatmap.2(mat, Rowv=NULL, Colv=NULL, col = c(heat.colors(4, alpha = 1), "gray"), breaks = c(0, 0.01, 0.05, 0.075, 0.1, 1), trace = "none", dendrogram = "none", density.info = "none", margins=c(12, 8)) -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] heatmap.2() yielding an inappropriate key?
Esteemed R-users, heatmap.2() is yielding an inappropriate key based on my colors and break-points. In the reproducible example below, the key is inappropriate (to me) because- 1. 'Orange' is simply not represented in the key, despite its prescence in the heatmap. 2. The proportions of the key are clearly out, ie., my largest bin, (0.1 - 0.2) is half the range, but this bin (colored "gray") clearly extnds bellow the "0.1" tick mark of the key, beyond its specified bin. What am i missing/doing wrong? Or for a key set up like this example is heatmap.2() unsuitable, necessitating production with another graphics functions? If so, recommendations appreciated. I have tried ggplot2, but struggle getting this function producing what i need. And i just need to make a nice key at this point. All thoughts and suggestions greatly appreciated. cheers, karl #reproducible example: library(gplots) set.seed(5) mat <- matrix(runif(50, min=0, max=0.2), nrow = 10, ncol = 5) heatmap.2(mat, Rowv=NULL, Colv=NULL, col = c(heat.colors(4, alpha = 1), "gray"), breaks = c(0, 0.01, 0.05, 0.075, 0.1, 1), trace = "none", dendrogram = "none", density.info = "none", margins=c(12, 8)) -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] heatmap.2 - change column & row locations; angle / rotate
Esteemed R user's, I'm struggling to achieve some details of a heatmap using heatmap.2(): 1. Change label locations, for both rows & columns from the default right & bottom, to left and top. Can this be done within heatmap.2()? Or do i need to suppress this default behavior (how) and call a new function to relabel (what) specifying locations? 2. Change the angle of the labels. By default column labels are 90deg anti-clock-wise from horizontal. How to bring them back to horizontal? Or better, rotate 45deg clock-wise from horizontal (ie., rotate 135deg a.clock.wise from default)? Any suggestions or pointers to helpful resources greatly appreciated, Karl -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why the variation when creating .pdf file output for my plots?
Thank you Erik! That works nicely now. The file size in (in kilobytes) is equal to the "File>Save As>PDF" method. Still curious why the file sizes (in Kb), differ by a factor of ~2 between the two methods: pdf() dev2bitmap(method = "pdf") I'm just *assuming* here that file size is inidcative of image quality. Is this assumption correct? If so, how would one increase .pdf quality within the dev2bitmap() function? With thanks for any further thoughts on this, cheers, Karl On 6/30/2010 4:58 PM, Erik Iverson wrote: Method 3: > pdf(file="my_plot.pdf", paper="a4") > dev.off() The `pdf` function opens a *new* graphics device, you then send output to the device before calling dev.off(), e.g., pdf(file = my_plot.pdf") plot(1:10, 1:10) dev.off() -yields a .pdf file of 1kb (same plot example) and returns the following error when attempting to open with Adobe acrobat: "There was an error opening this document. This file cannot be opened because it has no pages." -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why the variation when creating .pdf file output for my plots?
Esteemed R Users, Would some one be patient enough to explain the variation i see when creating .pdf file output for my plots? FYI- my goal is produce the highest quality .pdf output from the R 'command line' as opposed to using the menu of the acitve graphics window. Im using 32bit WinXP. Session info at the bottom. I have Ghostscript v8.71 installed and in the Path such that C:\gswin32c.exe runs said program. All shared insights appreciated! Karl Method 1: In the R graphics device window, form the menu File>Save As>PDF -yields a .pdf file of 700Kb (in this plot example) Method 2: > dev2bitmap(file="expression.density.plotb.pdf", type = "pdfwrite", > method = "pdf") > dev.off() -yields a .pdf file of 300kb (same plot example) indistinguiashble (on the screen atleast) from method 1. Method 3: > pdf(file="my_plot.pdf", paper="a4") > dev.off() -yields a .pdf file of 1kb (same plot example) and returns the following error when attempting to open with Adobe acrobat: "There was an error opening this document. This file cannot be opened because it has no pages." SessionInfo() R version 2.10.1 (2009-12-14) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] grDevices datasets splines graphics stats tcltk utils methods [9] base other attached packages: [1] affy_1.24.2 Biobase_2.6.1 gdata_2.7.1 svSocket_0.9-48 TinnR_1.0.3 [6] R2HTML_1.59-1 Hmisc_3.7-0 survival_2.35-7 loaded via a namespace (and not attached): [1] affyio_1.14.0cluster_1.12.1 grid_2.10.1 [4] gtools_2.6.1 lattice_0.17-26 preprocessCore_1.8.0 [7] svMisc_0.9-56tools_2.10.1 -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] several common sub-axes within multiple plot area
Cheers Greg, That's really simple. That's excellent. Thank you. Sincere thanks for the education. The more i learn, the more i like getting it done with R. karl On 6/28/2010 7:32 PM, Greg Snow wrote: How about: #my example: dev.new() layout( rbind( c(1,2), c(7,7), c(3,4), c(8,8), c(5,6), c(9,9) ), heights=c(10,1,10,1,10,1) ) #Graph 1: plot(rnorm(20), rnorm(20), xlab = "Results 1 (Int)", ylab = "Variable A", main = "Factor X") #Graph 2: plot(rnorm(20), rnorm(20), xlab = "Results 1 (Int)", ylab = "Variable A", main = "Factor Y") #Graph 3: plot(rnorm(20), rnorm(20), xlab = "Results 2 (Int)", ylab = "Variable B") #Graph 4: plot(rnorm(20), rnorm(20), xlab = "Results 2 (Int)", ylab = "Variable B") #Graph 5: plot(rnorm(20), rnorm(20), xlab = "Results 3 (Int)", ylab = "Variable C") #Graph 6: plot(rnorm(20), rnorm(20), xlab = "Results 3 (Int)", ylab = "Variable C") par(mar=rep(0,4)) plot.new() text( .5, .5, "Results 1 (Int)", font=2, cex=1.5 ) plot.new() text( .5, .5, "Results 2 (Int)", font=2, cex=1.5 ) plot.new() text( .5, .5, "Results 3 (Int)", font=2, cex=1.5 ) -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] several common sub-axes within multiple plot area
Jim, What a great function: exactly as i needed. I'm sure i'll be finding alot of use for the plotrix package. Sincere thanks for your fast help, cheers, Karl On 6/27/2010 8:52 AM, Jim Lemon wrote: On 06/26/2010 11:20 PM, Karl Brand wrote: Dear List, I'd really appreciate tip's or code demonstrating how i can achieve some common axis labels integrated into a multiple plot. In my example (below), i'm trying to achieve: -a single "Results 1 (Int)" centered & btwn row 1 and row 2; -a single "Results 2 (Int)" centered & btwn row 2 and row 3; and, -a single "Results 3 (Int)" centered at the bottom, ie., below row 3. I played with mtext() and par(oma=... per this post- https://stat.ethz.ch/pipermail/r-help/2004-October/059453.html But have so far failed to achieve my goal. Can i succeed with something combined with the 'high level' plot() function? Or do i need to get specific with some low level commands (help!)? Hi Karl, Your request prompted me to have a look at the getFigCtr function in the plotrix package. All I had to do was to add an argument to adjust the proportion of the figure region that was calculated, and it will do what you want, I think. The new function will be in the next version. getFigCtr<-function(pos=c(0.5,0.5)) { pars<-par(c("usr","mar","fin","pin")) pxspan<-diff(pars$usr[1:2]) fxspan<-pxspan*pars$fin[1]/pars$pin[1] figxctr<- pars$usr[1]-(fxspan-pxspan)*pars$mar[2]/(pars$mar[2]+pars$mar[4]) + fxspan*pos[1] pyspan<-diff(pars$usr[3:4]) fyspan<-pyspan*pars$fin[2]/pars$pin[2] figyctr<- pars$usr[1]-(fyspan-pyspan)*pars$mar[1]/(pars$mar[1]+pars$mar[3]) + fyspan*pos[2] return(c(figxctr,figyctr)) } #my example: dev.new() plot.new() library(plotrix) par(mfrow=c(3,2)) #Graph 1: plot(rnorm(20), rnorm(20), xlab = "", ylab = "Variable A", main = "Factor X") #Graph 2: plot(rnorm(20), rnorm(20), xlab = "", ylab = "Variable A", main = "Factor Y") mtext("Results 1 (Int)",1,at=getFigCtr(c(0,0))[1],line=3) #Graph 3: plot(rnorm(20), rnorm(20), xlab = "", ylab = "Variable B") #Graph 4: plot(rnorm(20), rnorm(20), xlab = "", ylab = "Variable B") mtext("Results 2 (Int)",1,at=getFigCtr(c(0,0))[1],line=3) #Graph 5: plot(rnorm(20), rnorm(20), xlab = "", ylab = "Variable C") #Graph 6: plot(rnorm(20), rnorm(20), xlab = "", ylab = "Variable C") mtext("Results 3 (Int)",1,at=getFigCtr(c(0,0))[1],line=3) Jim -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] several common sub-axes within multiple plot area
Dear List, I'd really appreciate tip's or code demonstrating how i can achieve some common axis labels integrated into a multiple plot. In my example (below), i'm trying to achieve: -a single "Results 1 (Int)" centered & btwn row 1 and row 2; -a single "Results 2 (Int)" centered & btwn row 2 and row 3; and, -a single "Results 3 (Int)" centered at the bottom, ie., below row 3. I played with mtext() and par(oma=... per this post- https://stat.ethz.ch/pipermail/r-help/2004-October/059453.html But have so far failed to achieve my goal. Can i succeed with something combined with the 'high level' plot() function? Or do i need to get specific with some low level commands (help!)? With big thanks in advance for any suggestions/examples. cheers, Karl #my example: dev.new() plot.new() par(mfrow=c(3,2)) #Graph 1: plot(rnorm(20), rnorm(20), xlab = "Results 1 (Int)", ylab = "Variable A", main = "Factor X") #Graph 2: plot(rnorm(20), rnorm(20), xlab = "Results 1 (Int)", ylab = "Variable A", main = "Factor Y") #Graph 3: plot(rnorm(20), rnorm(20), xlab = "Results 2 (Int)", ylab = "Variable B") #Graph 4: plot(rnorm(20), rnorm(20), xlab = "Results 2 (Int)", ylab = "Variable B") #Graph 5: plot(rnorm(20), rnorm(20), xlab = "Results 3 (Int)", ylab = "Variable C") #Graph 6: plot(rnorm(20), rnorm(20), xlab = "Results 3 (Int)", ylab = "Variable C") -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] using the design matrix to correctly configure contrasts
Rich, Walmes, Thank you for enriching my understanding of the concept of "interaction": succinctly and clearly explained. I feel i can better phrase my question, the context being much clearer now. In my case, i want to see the simple effects of changing levels of time, whilst holding Photperiod and Tissue constant. And i wnat to do this for each of the (total) 6 levels of Photoperiod and Tissue. My poor working knowledge of R leaves me stuck, for now, with the default treatment constrasts i get when using the function model.matrix. In fact thats been fine, once i decoded the interpretation of the colnames of the model.matrix using available examples, at least for analyses no more complex than 2-way interactions. Now im faced with 3 factors, and a model.matrix where i am unble to see the constrasts im interested in explictly stated. Does this mean they are not possible, ie., i lack enough observations for the contrasts i want? If so then i'm still missing some basic concepts of ANOVA. #I have three photoperiod treatments: Pperiod <- factor(targets$Pperiod, levels = c("E", "L", "S")) #Two different tissues were sampled from each* subject: Tissue <- factor(targets$Tissue, levels = c("R", "C")) #*Such samples are said to be 'paired', no? Not sure how to deal with #this, how necessary dealing with it is, or how possible... #And where 16 unique subjects were sampled (for tissues "R" asnd "C" # at 16 different times giving the #third factor: Time <- factor(targets$Time, levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9","10","11","12","13","14","15", "16")) My primary question is- what changes occur across all times for each p.period and tissue combination., ie., "ER", "LR", "SR", "EC", "LC" & "SC"? Contrast wise, this appears straight forward to me for "ER", "LR", "SR" & "EC" which are explicit in the model.matrix i get from R (shown again below). That is, *assuming* my interpretation of the contrast is correct which is what my original post focused on. But, its just not obvious to me how "LC" and "SC" (for all times) contrasts can be specified. This is my practical problem i'm yet to overcome. And using the package "contrast" hasn't helped me overcome this so far (thank you no less Walmes). Further thoughts and advice gratefully received, Karl > colnames(design) [1] "(Intercept)" "Time2" [3] "Time3""Time4" [5] "Time5""Time6" [7] "Time7""Time8" [9] "Time9""Time10" [11] "Time11" "Time12" [13] "Time13" "Time14" [15] "Time15" "Time16" [17] "TissueC" "PperiodL" [19] "PperiodS" "Time2:TissueC" [21] "Time3:TissueC""Time4:TissueC" [23] "Time5:TissueC""Time6:TissueC" [25] "Time7:TissueC""Time8:TissueC" [27] "Time9:TissueC""Time10:TissueC" [29] "Time11:TissueC" "Time12:TissueC" [31] "Time13:TissueC" "Time14:TissueC" [33] "Time15:TissueC" "Time16:TissueC" [35] "Time2:PperiodL" "Time3:PperiodL" [37] "Time4:PperiodL" "Time5:PperiodL" [39] "Time6:PperiodL" "Time7:PperiodL" [41] "Time8:PperiodL" "Time9:PperiodL" [43] "Time10:PperiodL" "Time11:PperiodL" [45] "Time12:PperiodL" "Time13:PperiodL" [47] "Time14:PperiodL" "Time15:PperiodL" [49] "Time16:PperiodL" "Time2:PperiodS" [51] "Time3:PperiodS" "Time4:PperiodS" [53] "Time5:PperiodS" "Time6:PperiodS" [55] "Time7:PperiodS" "Time8:PperiodS" [57] "Time9:PperiodS" "Time10:PperiodS" [59] "Time11:PperiodS" "Time12:PperiodS" [61] "Time13:PperiodS" "Time14:PperiodS" [63] "Time15:PperiodS" "Time16:PperiodS" [65] "TissueC:PperiodL" "TissueC:PperiodS" On 6/2/2010 8:26 PM, RICHARD M. HEIBERGER wrote: Karl, The definition and interpretation of contrasts is part of any intermediate design of experiments text. Contrasts for interactions say that the effect of moving "from level 1 of A to le
Re: [R] using the design matrix to correctly configure contrasts
[Reposting to list] Thank you Rich. I still don't get it. If i understand correctly- the MMC example on maize data outlines an issue with the multiple ties between group means. As a result of this, "user specified contrasts" needed specifying. Its this part, understanding the design matrix (ie., the 'treatment contrast' for the ANOVA &/or lm design) so that one knows *how* to set up cunstom contrasts- the underlying logic- that i need to learn. Demystify. In this maize example, if it is explained, regretfully i missed it. Perhaps i'm making somthing out of nothing, its self evident and i'm just complicating it. In that case a bucket of cold water is what i need. But maybe you have another example? Or an explicit tutorial covering this? Unfortunatley the local stats here are thin on the ground and thus overworked. No time for "R-101" for troublsome biologists like me... Back to the miaze example in case i missed 'it', and with sincere thanks for your suggestion, karl On 6/1/2010 6:03 PM, RICHARD M. HEIBERGER wrote: > > Please look at the maiz example, the last example in ?MMC in the HH package. > Follow the example all the way to the end. It illustrates a problem and > then the resolution > of the problem. > install.packages("HH") ## if you don't have it yet. > library(HH) > ?MMC > Rich -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 On 6/1/2010 6:03 PM, RICHARD M. HEIBERGER wrote: Please look at the maiz example, the last example in ?MMC in the HH package. Follow the example all the way to the end. It illustrates a problem and then the resolution of the problem. install.packages("HH") ## if you don't have it yet. library(HH) ?MMC Rich -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] using the design matrix to correctly configure contrasts
Esteemed R-forum subscribers, I'm having a tough time configuring contrasts for my 3-way ANOVA. In short: I don't know how to configure (all) my contrasts correctly in order to specify (all) my comparisons of interest. I succeeded getting my contrasts of interest set up for a simpler 2-way ANOVA based on the fairly intuitive logic of the design col.names. But i'm not able to extend this logic to a more complex three way ANOVA. Obviously there *is* a logic to the "0's" and "1's" of R's design 'treatment contrast' matrix- i see that the "1's" correspond to each of the factors that an observation is associated with. But exactly how this information can be used to ascribe contrasts of interest remains beyond my understanding, especially where interaction is concerned. Googling for days didn't yield the help i was looking for. Can some one point me to a detailed explanation (suitable for R dilettantes) how to specify any contrast of interest given a design matrix? For anyone really needing some diversion, i'd *really* appreciate a personal explanation using my design as an example. Warning- its not small... #load limma package to analyse affy gene expression data library(limma) targets <- read.delim("targets.txt") #factors & levels Time <- factor(targets$Time, levels = c("t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", "t10", "t11", "t12", "t13", "t14", "t15", "t16")) Tissue <- factor(targets$Tissue, levels = c("R", "C")) Pperiod <- factor(targets$Pperiod, levels = c("E", "L", "S")) #model excluding the 3-way interaction (written for convenience to # build on previous 2-way ANOVA design <- model.matrix(~Time + Tissue + Pperiod + Time:Tissue + Time:Pperiod + Tissue:Pperiod) fit <- lmFit(rma.pp, design) #how does this design look: > colnames(design) [1] "(Intercept)" "Timet2" [3] "Timet3" "Timet4" [5] "Timet5" "Timet6" [7] "Timet7" "Timet8" [9] "Timet9" "Timet10" [11] "Timet11" "Timet12" [13] "Timet13" "Timet14" [15] "Timet15" "Timet16" [17] "TissueC" "PperiodL" [19] "PperiodS" "Timet2:TissueC" [21] "Timet3:TissueC" "Timet4:TissueC" [23] "Timet5:TissueC" "Timet6:TissueC" [25] "Timet7:TissueC" "Timet8:TissueC" [27] "Timet9:TissueC" "Timet10:TissueC" [29] "Timet11:TissueC" "Timet12:TissueC" [31] "Timet13:TissueC" "Timet14:TissueC" [33] "Timet15:TissueC" "Timet16:TissueC" [35] "Timet2:PperiodL" "Timet3:PperiodL" [37] "Timet4:PperiodL" "Timet5:PperiodL" [39] "Timet6:PperiodL" "Timet7:PperiodL" [41] "Timet8:PperiodL" "Timet9:PperiodL" [43] "Timet10:PperiodL" "Timet11:PperiodL" [45] "Timet12:PperiodL" "Timet13:PperiodL" [47] "Timet14:PperiodL" "Timet15:PperiodL" [49] "Timet16:PperiodL" "Timet2:PperiodS" [51] "Timet3:PperiodS" "Timet4:PperiodS" [53] "Timet5:PperiodS" "Timet6:PperiodS" [55] "Timet7:PperiodS" "Timet8:PperiodS" [57] "Timet9:PperiodS" "Timet10:PperiodS" [59] "Timet11:PperiodS" "Timet12:PperiodS" [61] "Timet13:PperiodS" "Timet14:PperiodS" [63] "Timet15:PperiodS" "Timet16:PperiodS" [65] "TissueC:PperiodL" "TissueC:PperiodS" #the contrasts that i believe i *can* work out correctly: cont.matrix <- cbind( t1.S.RvsAll.S.R.Times = c( 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0), t1.E.RvsAll.E.R.Times = c( 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), t1.L.RvsAll.L.R.Times = c( 0, 1, 1, 1, 1, 1, 1
Re: [R] Multivariate hypergeometric distribution version of phyper()
Peter, Chuck, Big thanks for your input. I will be following up each and every of your suggestions on the morrow. Something of note though that you may have further thoughts on- phyper() was *specifically* recommneded by BioC responders for my application in spite of the fact i originally thought a bootstrapping approach seemed most logical given a quasi dependency* between gene lists. I implore you to have a thorough read through my recent BioC thread here: http://permalink.gmane.org/gmane.science.biology.informatics.conductor/27909 After more than a week since posting on the BioC without response, i reposted here the question you now kindly addressed. Clearly i'm yet to resolve this by following up your suggestions, and any response you may offer on the BioC thread will no doubt be enlightening for me. Thanks again, Karl *Probably gene expression has varying levels of dependancy, but atleast for comparing the 3 lists i can say they all come from independent biological replicates (animals) which in theory doesn't violate any of phypers assumptions. Right? I won't go into my 2 gene-list comparisons which are between 'paired' tissues each derived from the same animals. They probably can not be considered truly independant... On 3/30/2010 7:04 PM, Peter Ehlers wrote: Karl, I strongly support Chuck's recommendations. If you do still want to compute such probabilities 'by hand', you could consider the lchoose() function which does work for your example. -Peter Ehlers On 2010-03-30 9:55, Charles C. Berry wrote: On Tue, 30 Mar 2010, Karl Brand wrote: Dear R Users, I employed the phyper() function to estimate the likelihood that the number of genes overlapping between 2 different lists of genes is due to chance. This appears to work appropriately. Now i want to try this with 3 lists of genes which phyper() does not appear to support. Some googling suggests i can utilize the Multivariate hypergeometric distribution to achieve this. eg.: http://en.wikipedia.org/wiki/Hypergeometric_distribution But when i try to do this manually using the choose() function (see attempt below example with just two gene lists) i'm unable to perform the calculations- the numbers hit infinity before getting an answer. Searching cran archives for "Multivariate hypergeometric" show this term in the vignettes of package's ‘combinat’ and ‘forward’. But i'm unable to make sense of the these pachakege functions in the context of my aforementioned apllication. Can some one suggest a function, script or method to achieve my goal of estimating the likelyhood of overlap between 3 lists of genes, ideally using the multivariate hypergeometric, or anything else for that matter? Two suggestions: 1) Don't! Likely the theory is unsuited for the application. In most applications that generate lists of genes, the genes are not iid realizations and the hypergeometric gives results that are astonishingly anticonservative. As an alternative , the block bootstrap may be suitable. See http://171.66.122.45/cgi/content/abstract/17/6/760 and Google (scholar) 'genomic "block bootstrap"' for some starting points. 2) Take this thread to the bioconductor list. You are much more likely to get pointers to useful packages and functions for genomic statistical software there. HTH, Chuck cheers in advance, Karl #example attempt with two gene lists m & n N <- 45101 # total number balls in urn m <- 720 # number of 'white' or 'special' balls in urn, aka 'success' n <- 801 # number balls drawn or number of samples k <- 40 # number of 'white' or 'special' balls DRAWN a <- choose(m,k) b <- choose((N-m),(n-k)) z <- choose(N,n) prK <- (a*b)/z #'the answer' print(prK) [1] NaN a [1] 7.985852e+65 b [1] Inf z [1] Inf -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 77
[R] Multivariate hypergeometric distribution version of phyper()
Dear R Users, I employed the phyper() function to estimate the likelihood that the number of genes overlapping between 2 different lists of genes is due to chance. This appears to work appropriately. Now i want to try this with 3 lists of genes which phyper() does not appear to support. Some googling suggests i can utilize the Multivariate hypergeometric distribution to achieve this. eg.: http://en.wikipedia.org/wiki/Hypergeometric_distribution But when i try to do this manually using the choose() function (see attempt below example with just two gene lists) i'm unable to perform the calculations- the numbers hit infinity before getting an answer. Searching cran archives for "Multivariate hypergeometric" show this term in the vignettes of package's ‘combinat’ and ‘forward’. But i'm unable to make sense of the these pachakege functions in the context of my aforementioned apllication. Can some one suggest a function, script or method to achieve my goal of estimating the likelyhood of overlap between 3 lists of genes, ideally using the multivariate hypergeometric, or anything else for that matter? cheers in advance, Karl #example attempt with two gene lists m & n N <- 45101 # total number balls in urn m <- 720 # number of 'white' or 'special' balls in urn, aka 'success' n <- 801 # number balls drawn or number of samples k <- 40# number of 'white' or 'special' balls DRAWN a <- choose(m,k) b <- choose((N-m),(n-k)) z <- choose(N,n) prK <- (a*b)/z #'the answer' print(prK) [1] NaN > a [1] 7.985852e+65 > b [1] Inf > z [1] Inf -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam T +31 (0)10 704 3457 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.