Re: [R] How to create a legend without plot, and to use scientific notation for axes label ?
Hi, How can I use formatC to convert 600 to 6e5 and not 6e+05 ? > formatC(60) [1] "6e+05" > formatC(60, format="e", digit=0) [1] "6e+05" -Original Message- From: Uwe Ligges [mailto:[EMAIL PROTECTED] Sent: Thursday, April 10, 2008 17:11 To: Ng Stanley Cc: r-help Subject: Re: [R] How to create a legend without plot, and to use scientific notation for axes label ? Uwe Ligges wrote: > > > Ng Stanley wrote: >> Hi, >> >> I have a 3 by 2 plots per page, and would like to place a legend on >> the last region. How to do that ? > > > Create an empty plot, e.g.: > > plot(1, type="n", axes=FALSE, xlab="", ylab="") > legend(1, 1, legend = c("Hello", "World"), col=1:2, >lwd=2, cex=3, xjust=0.5, yjust=0.5) > > Uwe Ligges > > > >> Also, is there any way to specify scientific notation for axes label ? Oh, I was too quick and forgot the 2nd question: Use axis() with formatC(). Uwe Ligges >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] conditional matching of rows of tables
Second try :P I have matrix A of 4 cols: 1 a 0 4 1 b 5 8 2 a 0 3 2 b 4 7 And matrix B of 3 cols: 1 2 3 2 4 5 2 0 3 1 7 8 I would like to assign (a or b) to the rows of matrix B. The rules are that in each row of matrix B, the 1st value must match the 1st col. of matrix A, 2nd and 3rd values must lie between 3rd and 4rd cols (inclusive) of matrix A. For example, the 1st row of matrix B is 1 2 3, the 1st value "1" corresponds to 1st and 2nd row of matrix A. Next, its 2nd and 3rd values "2" and "3" lie between "0" and "4" of 1st row of matrix A. Thus 1st row of matrix B is assigned "a". Similarly, the assignments for remaining rows of matrix B are 2 4 5 -> "b" 2 0 3 -> "a" 1 7 8 -> "b" -Original Message- From: jim holtman [mailto:[EMAIL PROTECTED] Sent: Friday, March 21, 2008 00:33 To: Ng Stanley Cc: r-help Subject: Re: [R] conditional matching of rows of tables Not exactly clear on the transformation that you want to do. In your example, '1 2 3 -> a', where does the '2 3' come from since I don't see a value of 2 in the 3rd & 4th columns. So a better explanation of what you are trying to do would be help and show where the values came from in each case. On 3/20/08, Ng Stanley <[EMAIL PROTECTED]> wrote: > Hi, > > Given matrix A of 4 cols. > > 1 a 0 4 > 1 b 5 8 > 2 a 0 3 > 2 b 4 7 > > I have another matrix B of 3 cols. How to assign (a or b) to the rows > such that in each row its 1st value must match the 1st col. of A, 2nd > and 3rd values must lie between 3rd and 4rd cols (inclusive) of A > > 1 2 3 -> a > 2 4 5 -> b > 2 0 3 -> a > 1 7 8 -> b > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Any one is porting or has ported prtools (http://www.prtools.org/) to R ?
Hi, Any one is porting or has ported prtools (http://www.prtools.org/) to R ? Thanks Stanley __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Conditional rows
That works beautfully. Why using test<=0.2 || test >0.3 gives error ? -Original Message- From: Gabor Csardi [mailto:[EMAIL PROTECTED] Sent: Monday, February 11, 2008 18:27 To: Ng Stanley Cc: r-help Subject: Re: [R] Conditional rows which(apply(test<=0.2, 1, all)) See ?which, ?all, and in particular ?apply. Gabor On Mon, Feb 11, 2008 at 06:22:09PM +0800, Ng Stanley wrote: > Hi, > > Given a simple example, test <- matrix(c(0.1, 0.2, 0.1, 0.2, 0.1, > 0.1, 0.3, 0.1, 0.1), 3, 3) > > How to generate row indexes for which their corresponding row values > are less than or equal to 0.2 ? For this example, row 2 and 3 are the > correct ones. > > Thanks > > [[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. -- Csardi Gabor <[EMAIL PROTECTED]>UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error message from apply()
Now I understand why 3 by 3 data2_1 works and not the 3x10 data2_1. How can I precompute thr and pass it safely to function(x) for the column operation ? -Original Message- From: jim holtman [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 06, 2008 11:33 To: Ng Stanley Cc: r-help Subject: Re: [R] error message from apply() You matrix only has 3 rows, so when you do 'apply(data2_1,2,...)' you are extracting columns which only have a length of 3 while thr has a length of 10 > str(data2_1) num [1:3, 1:10] 0.958 0.271 -0.950 -0.130 -0.754 ... > str(thr) num [1:10] 1.060 0.528 0.104 0.925 -0.256 ... > That is why you get the error message of a size mismatch. On Feb 5, 2008 10:21 PM, Ng Stanley <[EMAIL PROTECTED]> wrote: > Replacing colMeans by mean removed the warning messages. Thanks > > However, when I precompute thr, and pass it to function(x), the error > returns. Using the shorter data2_1, doesn't give any warnings. What is > happening ? > > data2_1 <- matrix(c(0.9584190, 0.2710325, -0.9495618, -0.1301772, > -0.7539687, 0.5344464, -0.8205933, 0.1581723, -0.5351588, 0.04448065, > 0.9936430, 0.2278786, -0.8160700, -0.3314779, -0.4047975, 0.1168152, > -0.7458182, - 0.2231588, -0.5051651, -0.74871174, 0.9450363, > 0.4797723, -0.9033313, - 0.5825065, 0.8523742, 0.7402795, -0.7134312, > -0.8162558, 0.6345438, - 0.05704138), 3,10) # data2_1 <- > matrix(c(0.9584190, 0.2710325, -0.9495618, -0.1301772, - 0.7539687, > 0.5344464, -0.8205933, 0.1581723, -0.5351588), 3,3) > > thr <- colMeans(data2_1, na.rm = TRUE) + sd(data2_1, na.rm = TRUE) > > num <- apply(data2_1, 2, function(x) { >sum(x > (thr), na.rm = TRUE) > }) > > > > On 2/6/08, jim holtman <[EMAIL PROTECTED]> wrote: > > > > The error message was coming from the call to colMeans where 'x' was > > not a matrix; it was a vector that resulted from the 'apply' call. > > Did you intend to use 'mean' instead like this example: > > > > > data2_1 <- matrix(c(0.9584190, 0.2710325, -0.9495618, -0.1301772, > > > - > > 0.7539687, > > + 0.5344464, -0.8205933, 0.1581723, -0.5351588, 0.04448065, > > + 0.9936430, 0.2278786, -0.8160700, -0.3314779, -0.4047975, > > + 0.1168152, -0.7458182, - 0.2231588, -0.5051651, -0.74871174, > > + 0.9450363, 0.4797723, -0.9033313, - 0.5825065, 0.8523742, > > + 0.7402795, -0.7134312, -0.8162558, 0.6345438, - 0.05704138), 3,10) > > > > > > num <- apply(data2_1, 2, function(x) {sum(x > (mean(x, na.rm = > > > TRUE) + > > + 1*sd(x, na.rm = TRUE)), na.rm = TRUE)}) > > > num > > [1] 0 1 1 1 0 0 1 1 0 0 > > > > > > > > > On Feb 5, 2008 8:43 PM, Ng Stanley <[EMAIL PROTECTED]> wrote: > > > Hi, > > > > > > I keep getting the error message. Please help. > > > > > > Error in colMeans(x, na.rm = TRUE) : 'x' must be an array of at least > > two > > > dimensions > > > > > > The codes are: > > > > > > data2_1 <- matrix(c(0.9584190, 0.2710325, -0.9495618, -0.1301772, > > > - > > 0.7539687, > > > 0.5344464, -0.8205933, 0.1581723, -0.5351588, 0.04448065, > > > 0.9936430, 0.2278786, -0.8160700, -0.3314779, -0.4047975, > > > 0.1168152, -0.7458182, - 0.2231588, -0.5051651, -0.74871174, > > > 0.9450363, 0.4797723, -0.9033313, - 0.5825065, 0.8523742, > > > 0.7402795, -0.7134312, -0.8162558, 0.6345438, - 0.05704138), 3,10) > > > > > > num <- apply(data2_1, 2, function(x) {sum(x > (colMeans(x, na.rm = > > > TRUE) > > + > > > 1*sd(x, na.rm = TRUE)), na.rm = TRUE)}) > > > > > >[[alternative HTML version deleted]] > > > > > > __ > > > R-help@r-project.org mailing list > > > https://stat.ethz.ch/mailman/listinfo/r-help > > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > > > > > -- > > Jim Holtman > > Cincinnati, OH > > +1 513 646 9390 > > > > What is the problem you are trying to solve? > > > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.