[R] package seriation- how to manage font size and label margin

2013-09-02 Thread Suparna Mitra
Hello R experts, I am trying to use hmap from package seriation or bertinplot. I have two questions: How can I specify smaller font? I tried with pushViewport(viewport(layout=grid.layout(nrow = 1, ncol = 2), + gp = gpar(fontsize = 8))) but didn't work for the font with bertinplot. Also for hmap

Re: [R] Ordering a matrix (and not losing the rownames)

2013-09-02 Thread arun
Hi Ramón, It is for the column index. For ex: tags_totals[order(tags_totals[,1],decreasing=TRUE),1,drop=FALSE] #same as previous solution as there is only one column.  #   [,1] #Grupos   23 #Wikis    15 #Glosarios    11 #Bases de datos    7 #Taller    5

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
Hi, You could try: A- matrix(unlist(read.table(text= 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 ,sep=,header=FALSE)),ncol=3,byrow=FALSE,dimnames=NULL) library(matrixStats)  res1-t(sapply(split(as.data.frame(A),as.numeric(gl(nrow(A),2,6))),colProds))  res1 #  [,1] [,2] [,3] #1    4   10   18 #2   63  

[R] Legend position

2013-09-02 Thread Moshiur Rahman
Dear R-helpers, I'm trying to combine two box plots having two dependent variables: var1- Orange.area and var2- Iridescent.area; two independent categorical factors (each has two levels - 'High' 'Low'): fact1- Quantity fact2- Quality the data frame (df) is: Quantity Quality

Re: [R] How to catch errors regarding the hessian in 'optim'

2013-09-02 Thread Prof J C Nash (U30A)
This may be one of the many mysteries of the internals of L-BFGS-B, which I have found fails from time to time. That is one of the reasons for Rvmmin and Rcgmin (and hopefully sooner rather than later Rtn - a truncated Newton method, currently working for unconstrained problems, but still

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread Bert Gunter
These elaborate manipulations are unnecessary and inefficient. Use indexing instead: j - 2*seq_len(nrow(A)/2) b - A[j,]*A[j-1,] b [,1] [,2] [,3] [1,]4 10 18 [2,] 63 64 63 [3,] 18 104 [,1] [,2] [,3] [1,]4 10 18 [2,] 63 64 63 [3,] 18 104 [,1]

[R] Multivariate discrete HMMs

2013-09-02 Thread Claus O'Rourke
Hi r-help, I have been using your RHmm package for some time and have recently had to try using the package for a new dataset. Basically I have a dataset with a number of discrete observation variables that change over time, and I would love to try modeling them using a HMM. Basically I was

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
Hi Bert, Thanks.  It is a better solution. If nrow() is not even. Anew- rbind(A,c(1,3,5)) j-seq_len(nrow(Anew)/2)###  Anew[j,]*Anew[j-1,] #Error in Anew[j, ] * Anew[j - 1, ] : non-conformable arrays t(sapply(split(as.data.frame(Anew),as.numeric(gl(nrow(Anew),2,7))),colProds))   [,1] [,2] [,3] 1 

[R] Sweave: printing an underscore in the output from an R command

2013-09-02 Thread David Epstein
I am working with Sweave and would like to print out into my latex document the result of the R command version$platform So what I first tried in my .Rnw document was \Sexpr{print(version$platform)}. However, the output from this command is the string x86_64-apple-darwin10.8.0 (without the

[R] Meaning of Integer,19

2013-09-02 Thread David Epstein
I tried example('apply'). Among the various examples, there was the following: apply z - array(1:24, dim = 2:4) apply zseq - apply(z, 1:2, function(x) seq_len(max(x))) apply zseq ## a 2 x 3 matrix [,1] [,2] [,3] [1,] Integer,19 Integer,21 Integer,23 [2,] Integer,20

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
I guess in such situations, fun1- function(mat){  if(nrow(mat)%%2==0){  j- 2*seq_len(nrow(mat)/2)  b- mat[j,]* mat[j-1,]  }  else {mat1- mat[-nrow(mat),]  j- 2*seq_len(nrow(mat1)/2)  b- rbind(mat1[j,]*mat1[j-1,],mat[nrow(mat),])   } b } fun1(A) # [,1] [,2] [,3] #[1,]    4   10   18 #[2,]  

Re: [R] Sweave: printing an underscore in the output from an R command

2013-09-02 Thread ONKELINX, Thierry
You have to escape the underscore \Sexpr{gsub(_, \_, print(version$platform))} Best regards, Thierry Van: r-help-boun...@r-project.org [r-help-boun...@r-project.org] namens David Epstein [david.epst...@warwick.ac.uk] Verzonden: maandag 2 september 2013

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
HI, In my first solutions:  n-3   t(sapply(split(as.data.frame(Anew),as.numeric(gl(nrow(Anew),n,nrow(Anew,colProds)) #  [,1] [,2] [,3] #1   28   80  162 #2  162   80   28 #3    1    3    5  n-4   t(sapply(split(as.data.frame(Anew),as.numeric(gl(nrow(Anew),n,nrow(Anew,colProds)) #  [,1]

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
Hi, No problem. n- 4 t(sapply(split(as.data.frame(Anew),as.numeric(gl(nrow(Anew),n,nrow(Anew,function(x) apply(x,2,prod)))  #  V1  V2   V3 #1 252 640 1134 #2  18  30   20 This could be a bit slow if you have big dataset. A.K. From: Edouard Hardy

Re: [R] Meaning of Integer,19

2013-09-02 Thread arun
Hi, If you check ?str() str(zseq) #List of 6 # $ : int [1:19] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:20] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:21] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:22] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:23] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:24] 1 2 3 4 5 6 7 8 9 10 ...

[R] quoted expressions in microbenchmark

2013-09-02 Thread Prof J C Nash (U30A)
I use microbenchmark to time various of my code segments and find it very useful. However, by accident I called it with the expression I wanted to time quoted. This simply measured the time to evaluate the quote. The following illustrates the difference. When explained, the issue is obvious,

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
HI, You could modify Bert's solution: n-3 j3-n*seq_len(nrow(A)/n) A[j3,]*A[j3-1,]*A[j3-2,]  ##assuming that nrow(dataset)%%n==0 # [,1] [,2] [,3] #[1,]   28   80  162 #[2,]  162   80   28 #Speed comparison set.seed(28) mat1- matrix(sample(1:20,1e5*3,replace=TRUE),ncol=3) n-4

Re: [R] How to catch errors regarding the hessian in 'optim'

2013-09-02 Thread Simon Zehnder
Dear John, thank you very much for your answer. I take a look at these packages (Rvmmin and Rcgmin). That sounds very interesting. For the example: The method relies on data which I always try to avoid to send on the r-help list - not that my data is confidential - but it becomes even more

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread Bert Gunter
## For arbitrary n, just loop over the lag! Here's an alternative version using logical instead of numerical indexing (assumes nrow(A) %% n = 0). You could also use the numerical indexing as before, of course. Doubt that it would make much of a speed difference, but you can try it and see. j -

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
Hi, You can try this: n- 3 j3-n*seq_len(nrow(A)/n) vec1- rep(j3,n) eval(parse(text=paste0(A,[,paste0(vec1,-,seq(n)-1),,],collapse=*))) # [,1] [,2] [,3] #[1,]   28   80  162 #[2,]  162   80   28 Just saw Bert's new solution: n-3  j - seq_len(nrow(A))%%n  b - A[j==0,]  for(i in seq_len(n-1))b -

Re: [R] Fisher test for a more than two group of genes‏

2013-09-02 Thread David Winsemius
On Aug 28, 2013, at 11:53 AM, Gabriel Wajnberg wrote: Good Afternoon, My name is Gabriel, I'm doing an analysis if there is increase or decrease in dependence on the mutated genes, using 3 or more genes using the fisher exact test.I performed with success an analysis for two genes using

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
Hi, Make sure you check the class of the columns.  I forgot about that. str(mat1)  int [1:10, 1:3] 1 2 10 18 2 16 1 18 12 19 ... Convert it to numeric. mat1New- sapply(split(mat1,col(mat1)),as.numeric) n- 40 nrow(mat1New)%%40 #[1] 0 system.time({ j40- n*seq_len(nrow(mat1New)/n)  vec1-

Re: [R] Sweave: printing an underscore in the output from an R command

2013-09-02 Thread Duncan Murdoch
On 13-09-02 3:18 PM, David Epstein wrote: Dear Thierry, Your suggestion doesn't work on my version of R. Here's what I get gsub(_, \_, print(version$platform) Error: '\_' is an unrecognized escape in character string starting \_ print(gsub(_, \_, version$platform)) Error: '\_' is an

Re: [R] Sweave: printing an underscore in the output from an R command

2013-09-02 Thread Yihui Xie
I think Thierry meant gsub(_, _, version$platform); he just typed too quickly. The point is to escape _ using \, but then people are often trapped in the dreams of dreams of dreams of backslashes like the movie Inception. And then due to a long-standing bug in Sweave for \Sexpr{} (sorry I

[R] restructure my data

2013-09-02 Thread Wim Kreinen
My data is in this form: var has 3 conditions (0,1,2) df var cauc 11 6462.3288 20 1585.2740 30 2481.6781 41 344.1781 50 8871.5753 62 816.7808 72 6031.3356 80 1013.5274 92 4913.5274 10 0 1517.2500 For the three conditions (0,1,2) I want the

[R] Questions about 'bigmemory'

2013-09-02 Thread Zhenfei Yuan
Dear R users, I'm now dealing with some big data set as big as 10GB, and my RAM got 16GB. Every time I run some models to this dataset using R, I have to first load it into RAM via read.csv, which spends lots time. I find the bigmemory package in the high performance task view of R, and tried

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread Edouard Hardy
Thank you all for your responses. The real problem is that all your answer work for products 2 by 2. I now have to do the product n by n row. Do you have a solution ? Thank you in advance, E.H. Edouard Hardy On Mon, Sep 2, 2013 at 5:43 PM, arun smartpink...@yahoo.com wrote: I guess in such

[R] help

2013-09-02 Thread 董忠信
tt - function(x) { obrien - function(x) { r - rank(x) (r - 0.5)/(0.5 + length(r) - r) } unlist(tapply(x, riskset, obrien)) } hi, i am newer in R. when dealing with a survival data, i have

[R] Convert chr pieces to numbers that have specific values defined by 2 vectors

2013-09-02 Thread tobias schlager
Dear all, I think this is an easy task, but I don't know how to do it. Specifically, I have 69 columns with 300.000 rows. In each cell there is a code like 2E3, 4RR, etc. I now have a list that replaces this with values, e.g., old new 2E3 5 4RR 3 etc. The list

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread Edouard Hardy
Thank you A.K. And do you have a solution without installing any package ? Thank you in advance. E.H. Edouard Hardy On Mon, Sep 2, 2013 at 5:56 PM, arun smartpink...@yahoo.com wrote: HI, In my first solutions: n-3

Re: [R] R dataframe and looping help

2013-09-02 Thread arun
HI, You may try this: dat1- read.table(text= CustID TripDate Store Bread Butter Milk Eggs 1 2-Jan-12 a 2 0 2 1 1 6-Jan-12 c 0 3 3 0 1 9-Jan-12 a 3 3 0 0 1 31-Mar-13 a 3 0 0 0 2 31-Aug-12 a 0 3 3 0 2 24-Sep-12 a 3 3 0 0 2 25-Sep-12 b 3 0 0 0 ,sep=,header=TRUE,stringsAsFactors=FALSE) dat2-

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread Bert Gunter
Gents: The eval(parse(...)) construction should almost always be avoided: it is basically a misuse of R. There are exceptions, I suppose, but this does not appear to be one of them. Note that the use of numeric indexing does appear to be slightly faster than logical indexing here, although I

Re: [R] Convert chr pieces to numbers that have specific values defined by 2 vectors

2013-09-02 Thread arun
Hi, You may try this: set.seed(285) dat1- as.data.frame(matrix(paste0(sample(1:10,100,replace=TRUE),sample(LETTERS[1:10],100,replace=TRUE)),10,10),stringsAsFactors=FALSE) set.seed(3490) dat2- data.frame(old=unique(unlist(dat1)),new=sample(1:100,63,replace=FALSE),stringsAsFactors=FALSE)  

Re: [R] Convert chr pieces to numbers that have specific values defined by 2 vectors

2013-09-02 Thread arun
Hi, On a bigger dataset: #Speed: set.seed(285) dat1- as.data.frame(matrix(paste0(sample(1:10,69*3e5,replace=TRUE),sample(LETTERS[1:10],69*3e5,replace=TRUE)),ncol=69,nrow=3e5),stringsAsFactors=FALSE) length(unique(unlist(dat1))) #[1] 100 set.seed(3490) dat2-

Re: [R] restructure my data

2013-09-02 Thread David Carlson
Thanks for the reproducible data set. The unstack() function produces a list of three vectors, one for each value of var, but it cannot combine them into a matrix since the number of entries in each is not the same. To get that you need to pad each vector with NAs: df - structure(list(var = c(1,

Re: [R] restructure my data

2013-09-02 Thread David Carlson
Sorry, there was a typo in my original message: df - structure(list(var = c(1, 0, 0, 1, 0, 2, 2, 0, 2, 0), + cauc = c(6462.32876712329, 1585.27397260274, 2481.67808219178, + 344.178082191781, 8871.57534246575, 816.780821917808, + 6031.33561643836, 1013.52739726027, 4913.52739726027, +

Re: [R] restructure my data

2013-09-02 Thread arun
Hi, You could try: df2- do.call(cbind,split(df[,-1],df[,1]))  res-sapply(seq_len(ncol(df2)),function(i) {x-df2[,i];x[duplicated(x)]-NA;x}) dimnames(res)- dimnames(df2) res #    0 1 2 #[1,] 1585.274 6462.3288  816.7808 #[2,] 2481.678  344.1781 6031.3356 #[3,] 8871.575   

[R] knitr: Was previously Sweave: printing an underscore in the output from an R command

2013-09-02 Thread David Epstein
Dear Yihui Thanks very much for drawing my attention to knitr, which I had not heard of before. Also thanks for pointing out the bug in Sweave, which I don't fully understand, but I don't want to spend time and effort on understanding it. So I hope you will find time to report the bug. I was

Re: [R] knitr: Was previously Sweave: printing an underscore in the output from an R command

2013-09-02 Thread Yihui Xie
On Mon, Sep 2, 2013 at 5:01 PM, David Epstein david.epst...@warwick.ac.uk wrote: Dear Yihui Thanks very much for drawing my attention to knitr, which I had not heard of before. Also thanks for pointing out the bug in Sweave, which I don't fully understand, but I don't want to spend time and

Re: [R] Issue with R libraries

2013-09-02 Thread Rolf Turner
On 31/08/13 22:35, prakashdevkumar wrote: I have an Ubuntu Quantal 12.10 Server 64-bit instance. Trying to install R libraries. Facing issue in installing library(qdap) library(openNLP) Can you suggest me how to go ahead. No one should reply to you until you learn that what you are trying to

[R] how to calculate bioclim for table dataset in dismo package

2013-09-02 Thread Kristi Glover
Hi R Experts, I was trying to develop model (bioclim, Domin) using a table data in 'dismo' package. The data I have is at table format instead of images (stack of raster images). I followed the procedures of dismo package to calculate the bioclim but I could not figure it out how I can

Re: [R] R dataframe and looping help

2013-09-02 Thread arun
HI Satish, colnames(Output)[4]- colnames(dat2)[i]; #guess this line should be: colnames(x1)[4]- colnames(dat2)[i] Regarding the warning, I used read.table(..., stringsAsFactors=FALSE).  In your case, you might need to either use that option while reading the data or convert the factor

[R] Question about the prediction plot in pls package

2013-09-02 Thread Euna Jeong
Hi, I'd like to draw the trained predictions and the cross-validated predictions in the same plot to compare two predictions. In page 3, in the pls Package paper, R plot(gas1, ncomp=2, asp = 1, line = TRUE) This shows only the cross-validated predictions. Could you tell me how to do? Thank

Re: [R] R dataframe and looping help

2013-09-02 Thread arun
HI, Try: res- lapply(seq_len(ncol(dat2)),function(i) { x1-cbind(dat1New[,c(1:4)],dat2[,i]); colnames(x1)[5]- colnames(dat2)[i]; x2-x1[x1[,5]!=0,]; x2$previoustripstore-ave(x2$Store,x2$CUSTID,FUN=function(x) c(,x[-length(x)])); x2$Nexttripstore- ave(x2$Store,x2$PANID,FUN=function(x) c(x[-1],)) x2