Re: [R] problem with abline and lines

2010-03-22 Thread Miguel Porto
Hi! You forgot to invert the slope: a perpendicular of 1/sqrt(2) should be -sqrt(2). Also, you should add asp=1 in the plot command to lock the aspect ratio, otherwise the scale of both X and Y may be different according to the size of the window: plot(x=c(-1, 1), y=c(-1, 1),asp=1); abline(a=0,

Re: [R] remove substring from each string vector component

2010-03-16 Thread Miguel Porto
Hi! It's just this easy: x=gsub(\t,,x) For more complex things, it's worth learning some regular expressions syntax. Miguel On Tue, Mar 16, 2010 at 2:50 PM, arnaud chozo arnaud.ch...@gmail.comwrote: Hi all, I have a string vector like that: x=c(1\t\t, 2, 3\t\t\t) I need to remove all the

Re: [R] for() loop

2010-03-15 Thread Miguel Porto
Hi, I usually use aggregate() for this: aggregate(datjan,list(datjan[,4]),sum) with the advantage that you can use any other aggregation function (mean, var and so on...). See help. Miguel On Sun, Mar 14, 2010 at 8:49 PM, Schmidt Martin m.schm...@students.unibe.ch wrote: Hello I'm

Re: [R] for() loop

2010-03-15 Thread Miguel Porto
Sorry, I missed the [,4] : aggregate(datjan[,4],by=list(datjan[,4]),sum) Miguel [[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] storing matrix(variables) in loop

2010-03-15 Thread Miguel Porto
Just in case... b=array(NA,c(3,3,3,4))# that means b[matrix-row,matrix-col,i,j] for (i in 1:3){ for (j in 1:4){ b[,,i,j]=matrix(runif(1),3,3) } } b (I think there are better ways to do this anyway...) Miguel [[alternative HTML version deleted]]

Re: [R] storing matrix(variables) in loop

2010-03-15 Thread Miguel Porto
Yeah, that sounds inefficient to me also. I think you'd be better off using multidimensional arrays instead of lists, since all your values are numeric. See ?array. Miguel 2010/3/15 Márcio Resende mresende...@yahoo.com.br Hello R-helpers, I have the following code that works well, b

Re: [R] Time in minutes

2010-03-15 Thread Miguel Porto
Hi! That should do it: yourtime$min+yourtime$hour*60 In case your object is of class POSIXlt. Otherwise, convert it with as.POSIXlt first. Miguel On Mon, Mar 15, 2010 at 3:57 PM, Carlos Nader tamanduabande...@gmail.comwrote: Hi there! I have some data in POSIXlt format: 2009-07-18

Re: [R] Creating named lists

2010-03-12 Thread Miguel Porto
Hi See if this function works for you (I didn't properly test it...): nlist=function(...) { a=list(...); names(a)=as.character(match.call()[2:(length(a)+1)]) return(a); } Ex: a=1:3 b=matrix(1:10,nc=2) nlist(a,b) $a [1] 1 2 3 $b [,1] [,2] [1,]16 [2,]27 [3,]

Re: [R] Return one value, print another

2010-03-12 Thread Miguel Porto
Hmm... do something like that, no need to change the global option (I used a named vector instead of a list, it's more convenient): eg - function(x, digits=4) { xbar - mean(x) sdx - sd(x) value - c(xbar, sdx) names(value) - c(Mean of X, SD of X) print(round(value,digits));

Re: [R] Return one value, print another

2010-03-12 Thread Miguel Porto
Yeah that's right; in that case implementing the print.myclass as you say would be the best option. Miguel On Fri, Mar 12, 2010 at 2:17 PM, Dieter Menne dieter.me...@menne-biomed.dewrote: Miguel Porto wrote: Hmm... do something like that, no need to change the global option (I used

Re: [R] Comparing matrices

2010-03-11 Thread Miguel Porto
Also look at ?any and ?all Very handy functions. Miguel On Thu, Mar 11, 2010 at 12:37 PM, Esmail esmail...@gmail.com wrote: Hello all, I have two matrices, pop and pop2, each the same number of rows and columns that I want to compare for equality. I am concerned about efficiency in

Re: [R] Can't convert list to matrix properly

2010-03-11 Thread Miguel Porto
Hi, Is this what you want? matrix(unlist(myList),nr=1) Miguel On Thu, Mar 11, 2010 at 4:03 PM, anna lippelann...@hotmail.com wrote: Hi guys, here is a list of names that I have: MyList: myList-list(A, B,C,D) myList [[1]] [1] A [[2]] [1] B [[3]] [1] C [[4]] [1] D I want to

Re: [R] Can't convert list to matrix properly

2010-03-11 Thread Miguel Porto
see for yourself - AFAIK it'll just concatenate eveverything which is atomic into a vector, thus losing all the structure associated. Miguel On Thu, Mar 11, 2010 at 4:14 PM, anna lippelann...@hotmail.com wrote: Yes, definitely! so unlist() turns the list components into a vector? What if

Re: [R] Joining elements of an array into a single element

2010-03-10 Thread Miguel Porto
Hello, If you do this after the for loop, you'll get what you want: paste(tre,collapse=) (you can use whatever separator you want in the collapse argument) But you don't even need the for loop, just do this instead of the for loop: paste(con(,p, == ,c,, ,zest,, ,sep=,collapse=) Best, Miguel

Re: [R] (box-) plot annotation: italic within paste?

2010-03-08 Thread Miguel Porto
Hello, Try this way (not sure if it's the best way, but it works): boxplot(x[,i], main=substitute(expression(paste(a, ,italic(b), ,c)),list(a=mainlabel1,b=predictor[i],c=mainlabel2)), ylab=paste(ylabel),cex.lab=cexalabel,cex.main=cexmlabel,cex.axis=1.5) Best, Miguel On Mon, Mar 8, 2010 at