[R] gsub and multiple replacements

2008-06-02 Thread Ng Stanley
Hi, I would like to replace A B by A-B and AA(DD) by AA using a single gsub. Is that possible besides using two gsub ? Thanks Stanley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

[R] How to get subset of rows and columns that are most strongly correlated ?

2008-05-16 Thread Ng Stanley
Hi, I have a relatively large matrix 20k rows and 1000 columns. Instead of trying all possible combinations, is there a way to identify subset of rows and columns that are most strongly correlated ? Thanks Stanley [[alternative HTML version deleted]]

[R] Optimization problem, to minimize the length(rle(B)$lengths) for all the rows and columns

2008-05-12 Thread Ng Stanley
Hi, how can I order the rows and columns of a matrix A to generate B, in order to minimize the length(rle(B)$lengths) for all the rows and columns ? set.seed(5) a - matrix(rnorm(200), nrow=20) a[a=0] - 0 a[a0] - 1 a [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,]01

[R] How to insert a vector or matrix into an existing matrix

2008-04-18 Thread Ng Stanley
Hi, Is there any functions to insert a vector or matrix into an existing matrix say between row 5 and 6 or column 8 and 9, without creating a temporary matrix ? Thanks Stanley [[alternative HTML version deleted]] __ R-help@r-project.org

[R] What objects will save.image saves ? And how to specify objects to be saved..

2008-04-16 Thread Ng Stanley
Hi, I have a R script that loads an image R.data, does some operations, then save to the R.data again. Suppose I have done some computation before loading the R script, will all the objects before the R script execution be saved to R.data ? If yes, how can I specify save.image to save only those

Re: [R] What objects will save.image saves ? And how to specify objects to be saved..

2008-04-16 Thread Ng Stanley
Read and reread, can't make out. Will try an experiment later On Wed, Apr 16, 2008 at 7:51 PM, Henrique Dallazuanna [EMAIL PROTECTED] wrote: See ?save On Wed, Apr 16, 2008 at 8:46 AM, Ng Stanley [EMAIL PROTECTED] wrote: Hi, I have a R script that loads an image R.data, does

[R] p-values always identical for t.test of certain group of samples, why ?

2008-04-15 Thread Ng Stanley
Hi, Given the following, a - rnorm(5) b - rnorm(5) c - rnorm(5) a.1g.scale - scale(c(a,b,c))[1:5] b.1g.scale - scale(c(a,b,c))[6:10] c.1g.scale - scale(c(a,b,c))[11:15] a.2g.scale - scale(c(a,b))[1:5] b.2g.scale - scale(c(a,b))[6:10] c.2g.scale - scale(c) a.3g.scale - scale(a) b.3g.scale -

[R] reusing custom functions, how to ?

2008-04-15 Thread Ng Stanley
Hi, I have created a number of custom functions, and hope to reuse them in other source files. How should I go about doing that ? Thanks Stanley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

[R] How to get assign an vector of words to associative array ?

2008-04-15 Thread Ng Stanley
Hi, How to get assign an vector of words to associative array ? a[[animal]] - c(dog, cat) Error in a[[animal]] - c(dog, cat) : more elements supplied than there are to replace Thanks stanley [[alternative HTML version deleted]] __

[R] How to test if t[[cat]] exists ?

2008-04-15 Thread Ng Stanley
Hi, t - list(cat=1) exists(t) [1] TRUE exists(t[[cat]]) Error: unexpected symbol in exists(t[[cat exists(t[[\cat\]]) [1] FALSE Thanks Stanley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] How to get assign an vector of words to associative array ?

2008-04-15 Thread Ng Stanley
Thanks that help. On Wed, Apr 16, 2008 at 8:46 AM, Duncan Murdoch [EMAIL PROTECTED] wrote: On 15/04/2008 8:36 PM, Ng Stanley wrote: Hi, How to get assign an vector of words to associative array ? a[[animal]] - c(dog, cat) Error in a[[animal]] - c(dog, cat) : more elements

[R] Associative array and How to store a set of objects ?

2008-04-14 Thread Ng Stanley
Hi, Two questions: A) Assuming OB is an object, how do I store 20 of OB in a vector or list ? B) Does R has something similar associative array to Perl ? For example, %our_friends = ('best', 'Don', 'good', 'Robert', 'worst', 'Joe'); $our_friends{'cool'} = Karen; Thanks Stanley

Re: [R] Associative array and How to store a set of objects ?

2008-04-14 Thread Ng Stanley
+0800, Ng Stanley wrote: Hi, Two questions: A) Assuming OB is an object, how do I store 20 of OB in a vector or list ? replicate(20, OB, simplify=FALSE) B) Does R has something similar associative array to Perl ? For example, %our_friends = ('best', 'Don', 'good', 'Robert', 'worst

[R] Initialize many variables to NUL, check whether an object exist

2008-04-14 Thread Ng Stanley
Hi, Two questions: A) I need to initialize many variables to NULL. So I created variable_names - c(a1, a2). What can I do to variable_names so that variable a1 is NULL and a2 is NULL ? B) How can I check whether an object exist ? Thanks Stanley [[alternative HTML version deleted]]

Re: [R] Initialize many variables to NUL, check whether an object exist

2008-04-14 Thread Ng Stanley
Hi, How can I force the assignment ? RG[[ABC]] - c(a, b) Error in RG[[ABC]] - c(a, b) : more elements supplied than there are to replace On Mon, Apr 14, 2008 at 9:53 PM, Gabor Csardi [EMAIL PROTECTED] wrote: On Mon, Apr 14, 2008 at 09:47:49PM +0800, Ng Stanley wrote: Hi, Two

[R] how to write a table to pdf

2008-04-14 Thread Ng Stanley
Hi, Is there a way to write a table to pdf ? I have checked write.table, it only writes to text file. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the

Re: [R] How to refer to rows using a vector of row names ?

2008-04-11 Thread Ng Stanley
I tried that, it will work well if the vector contain unique row names. However, my vector contain duplicate row names. On Fri, Apr 11, 2008 at 6:53 PM, Petr PIKAL [EMAIL PROTECTED] wrote: Hi [EMAIL PROTECTED] napsal dne 11.04.2008 12:46:11: Hi, How to refer to rows using a vector of

[R] How to refer to rows using a vector of row names ?

2008-04-11 Thread Ng Stanley
Hi, How to refer to rows using a vector of row names ? Thanks Stanley [[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

Re: [R] How to refer to rows using a vector of row names ?

2008-04-11 Thread Ng Stanley
That should work well too if my row names are integers only. However, they are strings of alphanumeric characters On Fri, Apr 11, 2008 at 7:56 PM, Philipp Pagel [EMAIL PROTECTED] wrote: On Fri, Apr 11, 2008 at 07:00:10PM +0800, Ng Stanley wrote: I tried that, it will work well if the vector

Re: [R] I have a 3 by 2 plots per page. How do I specify a title at the top centre of each page ?

2008-04-10 Thread Ng Stanley
Found the solution, p - par(mfrow = c(3, 2), oma = c(0, 0, 2.1, 0)) title(main = paste(Title is here), outer = TRUE, cex.main = 1.5, font.main = 4) On Thu, Apr 10, 2008 at 11:20 AM, Ng Stanley [EMAIL PROTECTED] wrote: Hi, I have a 3 by 2 plots per page. How do I specify a title at the top

[R] legend placement

2008-04-10 Thread Ng Stanley
Hi, I am plotting 5 charts using p - par(mfrow = c(3, 2), how can I place my legend in the last region ? I don't wan to put it into the margin. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

[R] Beautifying axis tick labels

2008-04-10 Thread Ng Stanley
Hi, For example, the y axis shows 0 50 150. Is there any way to beautify the tick labels to get 0 5 10 15, and at the top of y-axis x10^5 (superscript 5) ? My plots all have different ylim, how to perform the beautification automatically ? Thanks Stanley [[alternative HTML

[R] Correlation between two multi-dimensional matrices

2008-04-09 Thread Ng Stanley
Hi, Are there any methods for computing the correlation between two multi-dimensional matrices ? Will transforming the matrices into vectors and applying pearson be fine ? Any blind spots that I should be aware ? Thanks Stanley [[alternative HTML version deleted]]

[R] How to create a legend without plot, and to use scientific notation for axes label ?

2008-04-09 Thread Ng Stanley
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 ? Also, is there any way to specify scientific notation for axes label ? [[alternative HTML version deleted]] __ R-help@r-project.org

[R] I have a 3 by 2 plots per page. How do I specify a title at the top centre of each page ?

2008-04-09 Thread Ng Stanley
Hi, I have a 3 by 2 plots per page. How do I specify a title at the top centre of each page ? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting

[R] conditional matching of rows of tables

2008-03-20 Thread Ng Stanley
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

[R] How to plot the dendrogram or tree for kmeans ?

2008-03-19 Thread Ng Stanley
Hi, How to plot the dendrogram or tree for kmeans, like we do for hclust ? [[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

Re: [R] How to turn a string into a variable name ?

2008-03-14 Thread Ng Stanley
: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ng Stanley Sent: Friday, 14 March 2008 1:27 PM To: r-help Subject: [R] How to turn a string into a variable

[R] Where are the latest html help for R, base packages and Bioc packages ?

2008-03-14 Thread Ng Stanley
Hi, Can anyone direct me ? 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

[R] How to get the value of last element in a vector/array ?

2008-03-14 Thread Ng Stanley
Hi, a[length(a)] gives the value of last element. Is there an alternative without using functions ? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the

[R] How to cbind or rbind different lengths vectors/arrays without repeating the elements of the shorter vectors/arrays ?

2008-03-13 Thread Ng Stanley
Hi, How to cbind or rbind different lengths vectors/arrays without repeating the elements of the shorter vectors/arrays ? cbind(1:2, 1:10) [,1] [,2] [1,]11 [2,]22 [3,]13 [4,]24 [5,]15 [6,]26 [7,]17 [8,]28 [9,]1

[R] How to manipulate data according to groups ?

2008-03-13 Thread Ng Stanley
Hi, I have a two columns data, the first column are values, and second column are the groups. For this example, there are 3 groups 1,2,3. How can I manipulate the values in the first column according to groups, say I would like to find mean, sum, and standard deviation for the different groups ?

[R] how to generate bar charts with the standard deviation

2008-03-13 Thread Ng Stanley
Hi, I have the two vectors mean and sd of individual columns, but I am unsure how to generate bar charts with the standard deviation, even after looking the help of barplot and barplot.2. [[alternative HTML version deleted]] __

[R] How to turn a string into a variable name ?

2008-03-13 Thread Ng Stanley
Hi, For example, natural_nums - 1:10 even_nums - seq(2,10, by = 2) types - c(natural_nums, even_nums) What functions can be performed on types[1] to turn it into a variable name and not a string ? [[alternative HTML version deleted]] __

[R] How to generate column names for pairwise comparison

2008-03-11 Thread Ng Stanley
Hi, Given names - c(a, b, c, d). I would like to generate a vs. b, a vs. c, a vs. d, b vs. c, b vs. d, c vs. d Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help

[R] How to specify where add-on packages should be installed

2008-03-11 Thread Ng Stanley
Hi, I am running R on a cluster. Basic packages are installed at ~/MyHome/lib64/R/library/ and add-ons packages are installed at ~/R/x86_64-redhat-linux-gnu-library/2.5/. Both directories were created by R by default. Problems arises when I use add-on packages, R complains that they can't be

[R] questions about p.adjust

2008-03-05 Thread Ng Stanley
Hi, I have some questions about p.adjust. The false discovery rate is a less stringent condition than the family wise error rate, so these methods are more powerful than the others., these methods refer to FDR methods or FWER methods. Simply what are the differences/pros/cons of both classes of

[R] queries about bitmap()

2008-03-05 Thread Ng Stanley
Hi, There are different types of tiff methods in bitmap(), which one should be used for publication-quality pictures ? 'tiffcrle', 'tiffg3', 'tiffg32d', 'tiffg4', 'tifflzw', 'tiffpack', 'tiff12nc', 'tiff24nc', Thanks [[alternative HTML version deleted]]

Re: [R] unable to start device PNG and unable to open connection to X11 display

2008-03-03 Thread Ng Stanley
Hi, I consulted ?png, and it uses X11. is there any way to save plots into png, without using X11 ? On 3/3/08, Prof Brian Ripley [EMAIL PROTECTED] wrote: Please consult the help page for png. On Mon, 3 Mar 2008, Ng Stanley wrote: Hi, I have installed R on a computational cluster

[R] unable to start device PNG and unable to open connection to X11 display

2008-03-02 Thread Ng Stanley
Hi, I have installed R on a computational cluster, and am using putty to access R. Please help on how to solve the problem of saving png files. png(file=myplot.png, bg=transparent) Error in X11(paste(png::, filename, sep = ), width, height, pointsize, : unable to start device PNG In

[R] Grouping 30 arrays (geographical) of 1000 rows (individuals) by 20 columns (time-series data)

2008-03-01 Thread Ng Stanley
Hi, I have 30 arrays (geographical) of 1000 rows (individuals) by 20 columns (time-series data), and need to group arrays that are most similar. What packages and functions will be useful for this task ? Thanks Stanley [[alternative HTML version deleted]]

[R] problem with heatmap.2

2008-02-15 Thread Ng Stanley
Hi, temp1[1:6,] _XXX BB_XXX C_XXX D_XXX E_XXX SkHep1_XXX 500.75285 0.30630 0.56330 0.45755 0.496650.74685 630.35930-0.22725 0.04725 0.53955 0.563900.51170 69 -1.57515-1.67610 -1.61695 -1.11685 -0.00085 -1.89155 910.84640

[R] R equivalent of linux cut, paste, and grep ?

2008-02-14 Thread Ng Stanley
Hi, What functions should I use in order to perform the following steps: 1) Load a particular column (e.g., column 5) from a csv file 2) Append the column 5 to another csv file 3) select those rows that match specific keywords in column 5 [[alternative HTML version deleted]]

[R] How to check cy5 and cy3 values were lowess normalized

2008-02-14 Thread Ng Stanley
Hi, I have some microarray data, cy5 and cy3 values are in log2. Is there a way to check they have undergone lowess normalization ? Thanks Stanley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

[R] How to make t.test handle NA and essentially constant values ?

2008-02-12 Thread Ng Stanley
Hi, First problem: test - matrix(c(1,1,2,1), 2,2) apply(test, 1, function(x) { t.test(x) $p.value }) Error in t.test.default(x) : data are essentially constant Second problem: test - matrix(c(1,0,NA,1), 2,2) apply(test, 1, function(x) { t.test(x) $p.value }) Error in t.test.default(x) : not

[R] indices of rows containing one or more elements 0

2008-02-12 Thread Ng Stanley
Hi, Given test - matrix(c(0,2,0,1,3,5), 3,2) test[test0] [1] 2 1 3 5 These are values 0 which(test0) [1] 2 4 5 6 These are array indices of those values 0 which(apply(test0, 1, all)) [1] 2 This gives the row whose elements are all 0 I can't seem to get indices of rows containing one or

Re: [R] How to make t.test handle NA and essentially constant values ?

2008-02-12 Thread Ng Stanley
t-tests in a loop? If so there was a post very recently on this list about this: https://stat.ethz.ch/pipermail/r-help/2008-February/153254.html Richard. Ng Stanley wrote: Thanks. Someone please help to make t.test go through all the data and not to be disrupted by the two problems

Re: [R] How to make t.test handle NA and essentially constant values ?

2008-02-12 Thread Ng Stanley
Thanks. Someone please help to make t.test go through all the data and not to be disrupted by the two problems. On 2/12/08, Petr PIKAL [EMAIL PROTECTED] wrote: Hi [EMAIL PROTECTED] napsal dne 12.02.2008 09:09:23: Hi, First problem: test - matrix(c(1,1,2,1), 2,2) apply(test, 1,

Re: [R] How to make t.test handle NA and essentially constant values ?

2008-02-12 Thread Ng Stanley
I met with a problem. The previous post dealt with loop, but mine is used in apply(). Please help. On 2/12/08, Ng Stanley [EMAIL PROTECTED] wrote: Thanks, that problem looks very similar to mine. try is a nice hack. I was thinking t.test would be intelligent enough to display NA

[R] Conditional rows

2008-02-11 Thread Ng Stanley
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

[R] How to generate table output of t-test

2008-02-05 Thread Ng Stanley
Hi, Given test - matrix(c(1, 1,2,2), 2,2) t - apply(test, 1, t.test) How can I obtain a table of p-values, confidence interval etc, instead of [[1]] One Sample t-test data: newX[, i] t = 3, df = 1, p-value = 0.2048 alternative hypothesis: true mean is not equal to 0 95 percent

[R] error message from apply()

2008-02-05 Thread Ng Stanley
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,

Re: [R] error message from apply()

2008-02-05 Thread Ng Stanley
, - + 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

[R] Warnings from apply longer object length is not a multiple of shorter object length

2008-02-04 Thread Ng Stanley
Hi, What was I doing wrong, such that B) gave warning messages ? I want the computation of thr to be outside the apply function. A) Uses a simple matrix of 9 elements. No warning messages. data2_1 - matrix (c(1,2,3,NA,4,5,NA,NA,6), 3,3) mean - colMeans(data2_1, na.rm = TRUE) sd - sd(data2_1,

[R] problem getting multiple densityplots on one page

2008-02-01 Thread Ng Stanley
Hi, I used the following statements to generate unsuccessfully a 5 by 5 multiple densityplots on a single page. If I use plot, the whole thing works. data - matrix(rnorm(25), 5, 5) op - par(mfrow = c(5, 5)) for (x in 1:5) {densityplot(data[,x])} par(op) Thanks Stanley [[alternative

[R] Bug with hist() ?

2008-01-31 Thread Ng Stanley
Hi, Is this a bug from hist() ? The total density is greater than 1. test [1] 0.05077802 -0.50585520 -0.98053648 -0.35513059 0.86767129 0.61736097 [7] 0.14264062 0.26243841 -0.41477782 0.64172618 0.87230953 -0.62570629 [13] 0.43596467 -0.93214106 -0.26781599 h - hist(test, freq =

[R] permutates and/or samples a matrix

2008-01-31 Thread Ng Stanley
Hi, sample(x) only permutates and/or samples from a vector, which I can't use for a matrix. Please help. Thanks Stanley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help

[R] Cannot save histogram picture when run from script

2008-01-31 Thread Ng Stanley
Hi, I am faced with a strange problem. My picture file is empty when the following statements were run from R script. But the picture file shows up correctly, when the commands are individually run from Rgui. png(file=histogram_correlation.png, bg = white) require(stats) histogram( ~ height |

[R] add/subtract matrices, ignoring NA or missing values

2008-01-28 Thread Ng Stanley
Hi, For example, given two 2x2 matrices m1 and m2. I would like to add/subtract element by element m1 [,1] [,2] [1,] NA NA [2,]12 m2 [,1] [,2] [1,]1 NA [2,] NA2 m1 + m2 [,1] [,2] [1,] NA NA [2,] NA4 How can I ignore the NA, and get