[R] apply, lapply and data.frame in R 2.5

2007-07-30 Thread jiho
Hello everyone, A recent (in 2.5 I suspect) change in R is giving me trouble. I want to apply a function (tolower) to all the columns of a data.frame and get a data.frame in return. Currently, on a data.frame, both apply (for arrays) and lapply (for lists) work, but each returns its native

Re: [R] apply, lapply and data.frame in R 2.5

2007-07-30 Thread Prof Brian Ripley
On Mon, 30 Jul 2007, jiho wrote: Hello everyone, A recent (in 2.5 I suspect) change in R is giving me trouble. I want to apply a function (tolower) to all the columns of a data.frame and get a data.frame in return. Currently, on a data.frame, both apply (for arrays) and lapply (for lists)

Re: [R] apply, lapply and data.frame in R 2.5

2007-07-30 Thread jiho
On 2007-July-30 , at 12:20 , Prof Brian Ripley wrote: On Mon, 30 Jul 2007, jiho wrote: A recent (in 2.5 I suspect) change in R is giving me trouble. I want to apply a function (tolower) to all the columns of a data.frame and get a data.frame in return. Currently, on a data.frame, both apply

[R] apply incompatible dimensions error

2007-07-24 Thread Bernzweig, Bruce \(Consultant\)
Hi, I've created the following two matrices (mat1 and mat2) and a function (f) to calculate the correlations between the two on a row by row basis. mat1 - matrix(sample(1:500,50), ncol = 5, dimnames=list(paste(row, 1:10, sep=), paste(col, 1:5, sep=)))

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Gabor Grothendieck
Your apply is trying to take the correlations of the rows of mat1 with the columns of mat2 which, of course, does not work if they have different numbers of columns. I think you mean to take the correlations of the columns of mat1 with the columns of mat2. For example, to take the correlations of

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Benilton Carvalho
are you positive that your function is doing what you expect it to do? it looks like you want something like: sapply(1:10, function(i) cor(mat1[i,], mat2[i,])) b On Jul 24, 2007, at 11:05 AM, Bernzweig, Bruce ((Consultant)) wrote: Hi, I've created the following two matrices (mat1 and mat2)

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Bernzweig, Bruce \(Consultant\)
-Original Message- From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 24, 2007 11:31 AM To: Bernzweig, Bruce (Consultant) Cc: r-help@stat.math.ethz.ch Subject: Re: [R] apply incompatible dimensions error Your apply is trying to take the correlations of the rows of mat1

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Gabor Grothendieck
PROTECTED] Sent: Tuesday, July 24, 2007 11:31 AM To: Bernzweig, Bruce (Consultant) Cc: r-help@stat.math.ethz.ch Subject: Re: [R] apply incompatible dimensions error Your apply is trying to take the correlations of the rows of mat1 with the columns of mat2 which, of course, does not work

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Benilton Carvalho
, Bruce (Consultant) Cc: r-help@stat.math.ethz.ch Subject: Re: [R] apply incompatible dimensions error are you positive that your function is doing what you expect it to do? it looks like you want something like: sapply(1:10, function(i) cor(mat1[i,], mat2[i,])) b On Jul 24, 2007, at 11:05

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Bernzweig, Bruce \(Consultant\)
-Original Message- From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 24, 2007 11:43 AM To: Bernzweig, Bruce (Consultant) Cc: r-help@stat.math.ethz.ch Subject: Re: [R] apply incompatible dimensions error Then try this: cor(t(mat1), t(mat2)) Also note 1. the above

Re: [R] apply incompatible dimensions error

2007-07-24 Thread Bernzweig, Bruce \(Consultant\)
- Bruce -Original Message- From: Benilton Carvalho [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 24, 2007 11:31 AM To: Bernzweig, Bruce (Consultant) Cc: r-help@stat.math.ethz.ch Subject: Re: [R] apply incompatible dimensions error are you positive that your function is doing what you

[R] apply a function to loop through

2007-07-17 Thread Hai Lin
Dear R users, I have a dataset generated as follows, myDat - data.frame(matrix(c(rep(LETTERS[1:3], each=5), rnorm(5,mean=3,sd=0.03), rnorm(5,12,1), rnorm(5,1,0.5)), ncol=2,

Re: [R] apply a function to loop through

2007-07-17 Thread Weiwei Shi
Hi, first of all, your Scores are factors instead of numeric, you need to change it; I made a new myDat for test purpose by myDat = as.data.frame(rbind(myDat, myDat)) myDat[16:30, 3] - gene2 myDat tissueScores Grp a A 3.01494535196933 gene1 b A 2.99647624484379

Re: [R] apply( )

2007-05-11 Thread Greg Tarpinian
Thank you all for your answers... To summarize, 1. with(X, ifelse(V1 V2 | V1 V3, 1, 0)) 2. ifelse((foo$x foo$y) | (foo$x foo$z), 1, 0) 3. with(foo, (x y) * (x z)) were the responses to my question (see below). Kindly, Greg --- Original post --- I have a

Re: [R] apply( )

2007-05-11 Thread Petr PIKAL
Hi [EMAIL PROTECTED] napsal dne 10.05.2007 17:59:22: or with(foo, (x y) * (x z)) Should not it be with(foo, ((x y) | (x z))*1) Regards Petr On 5/10/07, jim holtman [EMAIL PROTECTED] wrote: You don't need apply. Just do foo$result - ifelse((foo$x foo$y) | (foo$x

[R] apply( )

2007-05-10 Thread Greg Tarpinian
I have a question that must have a simple answer (but eludes me). I need a row-by-row logical comparison across three numeric variables in a data frame: foo$x, foo$y, foo$z. The logic is if( x y || x z ) 1 else 0 for a particular row. It is simple and very inefficient to use for(i in

Re: [R] apply( )

2007-05-10 Thread jim holtman
You don't need apply. Just do foo$result - ifelse((foo$x foo$y) | (foo$x foo$z), 1, 0) On 5/10/07, Greg Tarpinian [EMAIL PROTECTED] wrote: I have a question that must have a simple answer (but eludes me). I need a row-by-row logical comparison across three numeric variables in a data

Re: [R] apply( )

2007-05-10 Thread Chuck Cleland
Greg Tarpinian wrote: I have a question that must have a simple answer (but eludes me). I need a row-by-row logical comparison across three numeric variables in a data frame: foo$x, foo$y, foo$z. The logic is if( x y || x z ) 1 else 0 for a particular row. It is simple and very

Re: [R] apply( )

2007-05-10 Thread Gabor Grothendieck
or with(foo, (x y) * (x z)) On 5/10/07, jim holtman [EMAIL PROTECTED] wrote: You don't need apply. Just do foo$result - ifelse((foo$x foo$y) | (foo$x foo$z), 1, 0) On 5/10/07, Greg Tarpinian [EMAIL PROTECTED] wrote: I have a question that must have a simple answer (but eludes me).

Re: [R] apply( )

2007-05-10 Thread Petr Klasterecky
ifelse(((x y) | (x z)), 1, 0) Note in particular the use of | instead of || for elementwise comparisons. Petr Greg Tarpinian napsal(a): I have a question that must have a simple answer (but eludes me). I need a row-by-row logical comparison across three numeric variables in a data frame:

Re: [R] apply( )

2007-05-10 Thread Gabor Grothendieck
Sorry, you wanted or, not and. with(foo, pmax(x y, x z)) with(foo, as.numeric(x y | x z)) with(foo, 1*(x y | x z)) On 5/10/07, Gabor Grothendieck [EMAIL PROTECTED] wrote: or with(foo, (x y) * (x z)) On 5/10/07, jim holtman [EMAIL PROTECTED] wrote: You don't need apply.

[R] apply problem

2007-04-13 Thread aedin culhane
Dear R-Help I am running apply on a data.frame containing factors and numeric columns. It appears to convert are columns into as.character? Does it convert data.frame into matrix? Is this expected? I wish it to recognise numerical columns and round numbers. Can I use another function instead

Re: [R] apply problem

2007-04-13 Thread Prof Brian Ripley
On Fri, 13 Apr 2007, aedin culhane wrote: Dear R-Help I am running apply on a data.frame containing factors and numeric columns. It appears to convert are columns into as.character? Does it convert data.frame into matrix? Is this expected? I wish it to recognise Yes, and quite explicit on

Re: [R] apply problem

2007-04-13 Thread Stephen Tucker
?apply says If X is not an array but has a dimension attribute, apply attempts to coerce it to an array via as.matrix if it is two-dimensional (e.g., data frames). . . It would probably be easiest with a FOR-LOOP, but you could also try something like the code below (and insert your operations

Re: [R] apply problem

2007-04-13 Thread Seth Falcon
aedin culhane [EMAIL PROTECTED] writes: Dear R-Help I am running apply on a data.frame containing factors and numeric columns. It appears to convert are columns into as.character? Does it convert data.frame into matrix? Is this expected? I wish it to recognise numerical columns and round

[R] apply ? function doesnt create object

2007-03-03 Thread bunny , lautloscrew.com
hello, i have written a function to extract certain lines from a matrix. the result is a matrix with 6 cols, named dynamically according to the functions arguments. the problem is now, that i'm not able to return the resultmatrix for further use. the object is not being created. example

Re: [R] apply ? function doesnt create object

2007-03-03 Thread Charilaos Skiadas
On Mar 3, 2007, at 4:28 PM, bunny , lautloscrew.com wrote: Please use - for assignments instead of = : getans = function(x=qids,bnr=1,type=block) { #generate name of matrix matnam=paste(ans,type,as.character(bnr),sep=) #display result matrix

[R] apply for list or list - array

2006-09-19 Thread Ahn ChaeHyung
Dear all, I have the following list, aa, composed of two 3*3 tables. I would like to use apply function to summarize it, but apply cannot handle list. I want to do it without using any interation. 1. Is there any function like apply for list? 2. Is there any way to transform that list to a

Re: [R] apply for list or list - array

2006-09-19 Thread Uwe Ligges
Ahn ChaeHyung wrote: Dear all, I have the following list, aa, composed of two 3*3 tables. I would like to use apply function to summarize it, but apply cannot handle list. I want to do it without using any interation. 1. Is there any function like apply for list? 2. Is there any way

Re: [R] apply for list or list - array

2006-09-19 Thread Roger Bivand
On Mon, 18 Sep 2006, Ahn ChaeHyung wrote: Dear all, I have the following list, aa, composed of two 3*3 tables. I would like to use apply function to summarize it, but apply cannot handle list. I want to do it without using any interation. 1. Is there any function like apply for list?

Re: [R] apply for list or list - array

2006-09-19 Thread Dimitris Rizopoulos
AM Subject: [R] apply for list or list - array Dear all, I have the following list, aa, composed of two 3*3 tables. I would like to use apply function to summarize it, but apply cannot handle list. I want to do it without using any interation. 1. Is there any function like apply

[R] apply least angle regression to generalized linear models

2006-08-18 Thread Mike Wolfgang
Hello list, I've been searching around trying to find whether somebody has written such a package of least angle regression on generalized linear models, like what Lasso2 package does. The extension to generalized linear models is briefly discussed in the comment by D. Madigan and G. Ridgeway. Is

Re: [R] apply least angle regression to generalized linear models

2006-08-18 Thread Marc Schwartz (via MN)
On Fri, 2006-08-18 at 11:17 -0400, Mike Wolfgang wrote: Hello list, I've been searching around trying to find whether somebody has written such a package of least angle regression on generalized linear models, like what Lasso2 package does. The extension to generalized linear models is

Re: [R] apply least angle regression to generalized linear models

2006-08-18 Thread Liaw, Andy
I believe `lars' does not currently fit glms. For that you'll probably need to look at `glar', at: http://www.insightful.com/Hesterberg/glars/default.asp HTH, Andy From: Marc Schwartz On Fri, 2006-08-18 at 11:17 -0400, Mike Wolfgang wrote: Hello list, I've been searching around

Re: [R] apply least angle regression to generalized linear models

2006-08-18 Thread Marc Schwartz (via MN)
Andy, Upon further review of the documentation for lars, you are correct. Thanks for the pointer to the work by Tim et al. Regards, Marc On Fri, 2006-08-18 at 12:48 -0400, Liaw, Andy wrote: I believe `lars' does not currently fit glms. For that you'll probably need to look at `glar', at:

[R] apply a function to several lists' components

2006-06-30 Thread Taka Matzmoto
Dear R-user I have 100 lists. Each list has several components. For example, data1 $a [1] 1 2 $b [1] 3 4 $c [1] 5 There are data1, data2,, data100. All lists have the same number and the same name of components. Is there any function I can use for applying to only a specific component

Re: [R] apply a function to several lists' components

2006-06-30 Thread JeeBee
Maybe this helps ( data1 = list(a=c(1,2), b=c(3,4), c=c(5,6,7)) ) ( data2 = list(a=c(10,11), b=c(30,40), c=c(70,80)) ) cc - NULL for(data in ls(pattern=^data[0-9]+$)) { cc - c(cc, with(get(data), c)) } mean(cc) JeeBee. On Fri, 30 Jun 2006 09:50:51 -0500, Taka Matzmoto wrote: Dear R-user

[R] apply, apply speed vs. traditional looping mechanisms

2006-05-14 Thread John Sorkin
Can someone tell me why apply (and apply) are faster in performing repeated operations than a for (or do) loop? I am looking for a technical explanation. Thanks, John John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics Baltimore VA Medical Center GRECC and University of Maryland School

Re: [R] apply, apply speed vs. traditional looping mechanisms

2006-05-14 Thread Prof Brian Ripley
On Sun, 14 May 2006, John Sorkin wrote: Can someone tell me why apply (and apply) are faster in performing repeated operations than a for (or do) loop? I am looking for a technical explanation. apply() is just a wrapper for a for loop. So it is not faster that at least one implementation

Re: [R] apply, apply speed vs. traditional looping mechanisms

2006-05-14 Thread John Sorkin
Prof Ripley, Many thanks for your reply. I did not mean to use apply twice, I meant to ask about apply and lapply. I understand your comment re: apply. I assume your comment about lapply is meant to mean that lapply is implemented in C code and therefore should be faster than a loop written in R.

[R] apply

2006-05-13 Thread karim\.regh
Dear Sir, I’am a new user of “R” Software. I thank you very much for this Software. By running the “R” 2.3.0 software I have encountred aproblem: I have downloaded the tseriesChaos package from CRAN. When I try to run any function of the the tseriesChaos package for example, the c2 function the

Re: [R] apply

2006-05-13 Thread Marc Schwartz
On Sat, 2006-05-13 at 23:02 +0200, karim.regh wrote: Dear Sir, Iam a new user of R Software. I thank you very much for this Software. By running the R 2.3.0 software I have encountred aproblem: I have downloaded the tseriesChaos package from CRAN. When I try to run any function of the the

[R] apply(table) miss factor structure

2006-04-19 Thread Cézar Freitas
Hi, all. I didn't find something similar to this problem in past list. I have a data frame (named restr) where some columns are factors, like you can see: table(restr[,p1]) 0 1 2 3 4 5 0 26 1 0 1 0 table(restr[,p2]) 0 1 2 3 4 5 6 0 13 11 1 2 1 0 When I use apply,

Re: [R] apply(table) miss factor structure

2006-04-19 Thread Dimitris Rizopoulos
://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Cézar Freitas [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Wednesday, April 19, 2006 3:50 PM Subject: [R] apply(table) miss factor structure Hi, all. I didn't

[R] apply(ing) to sum subset of a vector

2006-03-27 Thread Fred J.
Dear R users I am trying to sum selective elements of a vector but my solution is not cutting it. Example: g - 1:5; from - 1:3; to - 3:5; from to 1 3 2 4 3 5 so I expect 3 sums from g 1+2+3 that is 1 to 3 of g 2+3+4 that is 2 to 4 of g 3+4+5 that is 3

Re: [R] apply(ing) to sum subset of a vector

2006-03-27 Thread jim holtman
create a matrix and then use apply: g - 1:5; from - 1:3; to - 3:5; index - cbind(from,to) apply(index, 1, function(x) sum(g[x[1]:x[2]])) [1] 6 9 12 On 3/27/06, Fred J. [EMAIL PROTECTED] wrote: Dear R users I am trying to sum selective elements of a vector but my solution is

Re: [R] apply(ing) to sum subset of a vector

2006-03-27 Thread Jacques VESLOT
apply(cbind(from,to), 1, function(x) sum(g[x[1]:x[2]])) Fred J. a écrit : Dear R users I am trying to sum selective elements of a vector but my solution is not cutting it. Example: g - 1:5; from - 1:3; to - 3:5; from to 1 3 2 4 3 5 so I expect 3 sums from

[R] Apply and more argumnts function

2006-03-04 Thread Andrej Kastrin
Dear useRs, shame on me, but I have no idea how to apply two arguments function on my data. I have 2 vectors, 'n' and 'm' and the function below: n - c(10,30,50,1000) m - c(10,50,100,200) MonteCarlo - function(n,m){ temp - NULL for(i in 1:m){ temp - c(temp,walk(n)) # walk is external

[R] apply

2006-01-13 Thread Guenther, Cameron
Hello, I have a dataset d which is d pop catch 1 66462.01 10807.757 2 87486.73 46257.885 3 57211.64 9345.058 4 71321.62 4892.868 5 100024.89 27334.248 6 104504.91 48535.092 7 95295.51 39348.195 8 93737.35 34343.489 9 89375.05 28750.743 10 95312.65

Re: [R] apply

2006-01-13 Thread Berton Gunter
is to catalyze the scientific learning process. - George E. P. Box -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Guenther, Cameron Sent: Friday, January 13, 2006 11:03 AM To: [EMAIL PROTECTED] Subject: [R] apply Hello, I have a dataset d

Re: [R] apply

2006-01-13 Thread Sundar Dorai-Raj
PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Guenther, Cameron Sent: Friday, January 13, 2006 11:03 AM To: [EMAIL PROTECTED] Subject: [R] apply Hello, I have a dataset d which is d pop catch 1 66462.01 10807.757 2 87486.73 46257.885 3 57211.64 9345.058 4 71321.62

[R] apply() and dropped dimensions

2005-12-05 Thread Robin Hankin
Hi I am having difficulty with apply(). I want apply() to return a matrix, but sometimes a vector is returned. Toy example follows. Function jj() takes a couple of matrices m1 and m2 as arguments and returns a matrix with r rows and c columns where r=nrow(m2) and c=nrow(m1). jj -

Re: [R] apply() and dropped dimensions

2005-12-05 Thread Berwin A Turlach
G'day Robin, RH == Robin Hankin [EMAIL PROTECTED] writes: RH How do I rewrite jj() so that it consistently returns a RH matrix? How about explicitly returning a matrix with the desired dimensions? jj function(m1,m2,f,...) matrix(apply(m1, 1, function(y) apply(m2,

[R] apply and plot

2005-10-13 Thread Luis Ridao Cruz
R-help, I use the code below to plot some data by applying apply function. But I don't know how I can get the argument type or col on the plot function to distinguish the different lines in the graph: apply ( my.data, 2, function ( x ) lines ( dimnames ( my.data ) [[1]] , x ) ) Thank you in

Re: [R] apply and plot

2005-10-13 Thread Marc Schwartz (via MN)
On Thu, 2005-10-13 at 14:50 +0100, Luis Ridao Cruz wrote: R-help, I use the code below to plot some data by applying apply function. But I don't know how I can get the argument type or col on the plot function to distinguish the different lines in the graph: apply ( my.data, 2, function

[R] Apply a function for each Row

2005-09-14 Thread Marc Bernard
Dear All, I wonder how to apply a given function to each row of a data frame. I've seen this function before but don't remember its name Thank you, Bernard - [[alternative HTML version deleted]]

Re: [R] Apply a function for each Row

2005-09-14 Thread Barry Rowlingson
Marc Bernard wrote: Dear All, I wonder how to apply a given function to each row of a data frame. I've seen this function before but don't remember its name You've just said it twice! 'apply'! Baz __ R-help@stat.math.ethz.ch mailing

Re: [R] Apply a function for each Row

2005-09-14 Thread Liaw, Andy
From: Barry Rowlingson Marc Bernard wrote: Dear All, I wonder how to apply a given function to each row of a data frame. I've seen this function before but don't remember its name You've just said it twice! 'apply'! A small catch: Marc wants to apply the function to

Re: [R] apply and arrays

2005-07-25 Thread Prof Brian Ripley
On Mon, 25 Jul 2005, Uwe Ligges wrote: Laura Holt wrote: Hi R! I have a 3 dimensional array, which is 21 x 3 x 3 I want to use apply to sum on each 21x3 matrix, which is fine. Is there a way that I can do this in 1 step instead of a loop (3), please? Don't know which direction you

[R] apply and arrays

2005-07-24 Thread Laura Holt
Hi R! I have a 3 dimensional array, which is 21 x 3 x 3 I want to use apply to sum on each 21x3 matrix, which is fine. Is there a way that I can do this in 1 step instead of a loop (3), please? thanks, Laura Holt mailto: [EMAIL PROTECTED] __

[R] apply the function factor to multiple columns

2005-05-31 Thread Bliese, Paul D LTC USAMH
I have a case where I would like to change multiple columns containing numbers to factors. I can change each column one at a time as in: TEMP.FACT$EXPOS01-factor(TEMP.FACT$EXPOS01,levels=c(1,2,3),labels=c(No ne,Low Impact,MedHigh Imp))

Re: [R] apply the function factor to multiple columns

2005-05-31 Thread Dimitris Rizopoulos
PROTECTED] To: r-help@stat.math.ethz.ch Sent: Tuesday, May 31, 2005 10:42 AM Subject: [R] apply the function factor to multiple columns I have a case where I would like to change multiple columns containing numbers to factors. I can change each column one at a time as in: TEMP.FACT$EXPOS01-factor

[R] apply question

2005-05-02 Thread Christoph Scherber
Dear R users, I´ve got a simple question but somehow I can´t find the solution: I have a data frame with columns 1-5 containing one set of integer values, and columns 6-10 containing another set of integer values. Columns 6-10 contain NA´s at some places. I now want to calculate (1) the number

Re: [R] apply question

2005-05-02 Thread Sean Davis
- Original Message - From: Christoph Scherber [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Monday, May 02, 2005 10:52 AM Subject: [R] apply question Dear R users, I´ve got a simple question but somehow I can´t find the solution: I have a data frame with columns 1-5 containing

RE: [R] apply question

2005-05-02 Thread Liaw, Andy
Try: ## Number of NAs in columns 6-10. colSums(is.na(data[6:10])) Col6 Col7 Col8 Col9 Col10 1 1 1 1 0 ## Number of NAs in each row of columns 6-10. rowSums(is.na(data[6:10])) 1 2 2 2 ## Sums of rows 1-5 omitting corresponding NAs in cols 6-10.

Re: [R] apply question

2005-05-02 Thread Dimitris Rizopoulos
/~m0390867/dimitris.htm - Original Message - From: Christoph Scherber [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Monday, May 02, 2005 4:52 PM Subject: [R] apply question Dear R users, I´ve got a simple question but somehow I can´t find the solution: I have a data frame with columns 1

Re: [R] apply question

2005-05-02 Thread Gabor Grothendieck
On 5/2/05, Christoph Scherber [EMAIL PROTECTED] wrote: Dear R users, I´ve got a simple question but somehow I can´t find the solution: I have a data frame with columns 1-5 containing one set of integer values, and columns 6-10 containing another set of integer values. Columns 6-10 contain

[R] apply vs sapply vs loop - lm() call appl(y)ied on array

2005-04-21 Thread Christoph Lehmann
Dear useRs (Code of the now mentioned small example is below) I have 7 * 8 * 9 = 504 series of data (each length 5). For each of theses series I want to compute a lm(), where the designmatrx X is the same for all these computations. The 504 series are in an array of dimension d.dim - c(5, 7, 8,

RE: [R] apply vs sapply vs loop - lm() call appl(y)ied on array

2005-04-21 Thread Wiener, Matthew
@stat.math.ethz.ch Subject: [R] apply vs sapply vs loop - lm() call appl(y)ied on array Dear useRs (Code of the now mentioned small example is below) I have 7 * 8 * 9 = 504 series of data (each length 5). For each of theses series I want to compute a lm(), where the designmatrx X is the same

Re: [R] apply vs sapply vs loop - lm() call appl(y)ied on array

2005-04-21 Thread Christoph Lehmann
it. The original post was from William Valdar, on April 19.) Hope this helps, Matt Wiener -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christoph Lehmann Sent: Thursday, April 21, 2005 9:24 AM To: R-help@stat.math.ethz.ch Subject: [R] apply vs sapply vs loop

[R] apply

2005-04-07 Thread malte
Hi, simple question I guess: the following line works well: aveBehav=c(apply(sdata, 2, mean)) However, I would like to pass an argument to the function mean, namely na.rm=TRUE Does anyone knows how to do this? Thanks in advance, Jan __

Re: [R] apply

2005-04-07 Thread Sean Davis
On Apr 7, 2005, at 8:27 AM, malte wrote: Hi, simple question I guess: the following line works well: aveBehav=c(apply(sdata, 2, mean)) However, I would like to pass an argument to the function mean, namely na.rm=TRUE apply(sdata,2,function(x) {mean(x,na.rm=TRUE)}) Sean

RE: [R] apply

2005-04-07 Thread Liaw, Andy
From: malte Hi, simple question I guess: the following line works well: aveBehav=c(apply(sdata, 2, mean)) However, I would like to pass an argument to the function mean, namely na.rm=TRUE Does anyone knows how to do this? aveBehav - apply(sdata, 2, mean, na.rm=TRUE) or

Re: [R] apply

2005-04-07 Thread Dimitris Rizopoulos
: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm - Original Message - From: malte [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Thursday, April 07, 2005 2:27 PM Subject: [R] apply Hi, simple

Re: [R] apply

2005-04-07 Thread Seth Falcon
malte [EMAIL PROTECTED] writes: aveBehav=c(apply(sdata, 2, mean)) aveBehav= apply(sdata, 2, mean, na.rm=TRUE) and ?apply will tell you about this. + seth __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE

Re: [R] apply

2005-04-07 Thread Petr Pikal
On 7 Apr 2005 at 14:27, malte wrote: Hi, simple question I guess: the following line works well: aveBehav=c(apply(sdata, 2, mean)) Hallo try aveBehav=c(apply(sdata, 2, mean, na.rm=T)) Cheers Petr However, I would like to pass an argument to the function mean, namely na.rm=TRUE

[R] apply a function to a rolling subset of a vector

2005-03-02 Thread Whit Armstrong
Does anyone know an easy way to calculate the rolling 20 period average or sum of a vector? For instance: x - rnorm(1000) y - apply.subset(x,20,fun=sum) The first element of y would contain the sum of elements 1 to 20, the second element of y would contain the sum of elements 2:21, and so on.

[R] apply a function to a rolling subset of a vector

2005-03-02 Thread Ken Knoblauch
Try this: ?convolve x-rnorm(1000) y-rep(1,20) z-convolve(x,y,type=filter) plot(x,type=l) str(z) num [1:981] 6.31 7.28 8.16 7.39 4.65 ... lines(c(rep(0,10),z,rep(0,10)),col=yellow,lwd=3) lines(c(rep(0,10),z,rep(0,10))/length(y),col=red,lwd=3) #running mean You wrote: Does anyone know an

Re: [R] apply a function to a rolling subset of a vector

2005-03-02 Thread Duncan Murdoch
On Wed, 2 Mar 2005 17:22:43 -0500, Whit Armstrong [EMAIL PROTECTED] wrote : Does anyone know an easy way to calculate the rolling 20 period average or sum of a vector? For instance: x - rnorm(1000) y - apply.subset(x,20,fun=sum) The first element of y would contain the sum of elements 1 to 20,

Re: [R] apply a function to a rolling subset of a vector

2005-03-02 Thread Marc Schwartz
On Wed, 2005-03-02 at 17:22 -0500, Whit Armstrong wrote: Does anyone know an easy way to calculate the rolling 20 period average or sum of a vector? For instance: x - rnorm(1000) y - apply.subset(x,20,fun=sum) The first element of y would contain the sum of elements 1 to 20, the

Re: [R] apply a function to a rolling subset of a vector

2005-03-02 Thread Gabor Grothendieck
Whit Armstrong whit at twinfieldscapital.com writes: : : Does anyone know an easy way to calculate the rolling 20 period average : or sum of a vector? : : For instance: : x - rnorm(1000) : : y - apply.subset(x,20,fun=sum) : : The first element of y would contain the sum of elements 1 to 20,

RE: [R] apply a function to a rolling subset of a vector

2005-03-02 Thread Whit Armstrong
: [R] apply a function to a rolling subset of a vector Whit Armstrong wrote: Does anyone know an easy way to calculate the rolling 20 period average or sum of a vector? For instance: x - rnorm(1000) y - apply.subset(x,20,fun=sum) help.search(rolling) gives me (among others) RollingAnalysis

RE: [R] apply for nested lists

2005-01-26 Thread Berton Gunter
:[EMAIL PROTECTED] On Behalf Of Alexandre Sanchez Pla Sent: Wednesday, January 26, 2005 8:50 AM To: r-help@stat.math.ethz.ch Subject: [R] apply for nested lists Hi, I am working with lists whose terms are lists whose terms are lists. Although the real ones contain locuslink identifiers

Re: [R] apply for nested lists

2005-01-26 Thread Gabor Grothendieck
Alexandre Sanchez Pla asanchez at ub.edu writes: : : Hi, : : I am working with lists whose terms are lists whose terms are lists. Although : the real ones contain locuslink identifiers and GO annotations (I work with the : Bioconductor GO) package, I have prepared an simplified example of

Re: [R] apply for nested lists

2005-01-26 Thread Kevin Bartz
Actually, what you want is sapply. sapply(tst.list, [[, VAL) Kevin Alexandre Sanchez Pla wrote: Hi, I am working with lists whose terms are lists whose terms are lists. Although the real ones contain locuslink identifiers and GO annotations (I work with the Bioconductor GO) package, I have

[R] apply function

2004-10-20 Thread Eric Pellegrini
Hi all, I have a question about apply function. Is that possible to pass some non-default arguments in the function we want to apply ? For example: if mat is a matrix and I want to use the tabulate function on its row. The command apply(mat,1,tabulate) works but I have problem with this one

RE: [R] apply function

2004-10-20 Thread Liaw, Andy
Try apply(mat, 1, tabulate, nbins=4). HTH, Andy From: Eric Pellegrini Hi all, I have a question about apply function. Is that possible to pass some non-default arguments in the function we want to apply ? For example: if mat is a matrix and I want to use the tabulate function on

Re: [R] apply function

2004-10-20 Thread Peter Dalgaard
Eric Pellegrini [EMAIL PROTECTED] writes: Hi all, I have a question about apply function. Is that possible to pass some non-default arguments in the function we want to apply ? For example: if mat is a matrix and I want to use the tabulate function on its row. The command

[R] apply ( , , table)

2004-08-24 Thread White . Denis
a - matrix (c( 7, 1, 1, 2, 6, 3, 4, 0, 1, 4, 5, 1, 8, 4, 4, 6, 1, 1, 2, 5), nrow=4, byrow=TRUE) b - apply (a, 1, table) apply documentation says clearly that if the rows of the result of FUN are the same length, then an array will be returned. And column-major would be the

Re: [R] apply ( , , table)

2004-08-24 Thread Tony Plate
apply() tries to be a bit smart about what it does (sometimes maybe too smart), but it actually is pretty useful a lot of the time. It's extremely widely used, so changing the behavior is not an option -- changing the behavior would break a lot of existing code. (Personally, I'd prefer it if

[R] apply on a data frame

2004-08-20 Thread Laura Holt
Hi R People: There are 2 data sets of the iris data: one is iris3, which is a 3-d array, and the other is iris, which is a data frame with 150 rows and 6 variables. Getting means is straightforward from the 3-day iris3 set: apply(iris3,c(2,3),mean) Setosa Versicolor Virginica Sepal L.

[R] apply and data frames

2004-08-20 Thread Laura Holt
Whoops! Just found it: by(iris[,1:4],Species,mean) Sorry for the inconvenience. Laura. Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the

[R] apply/looping query

2004-06-16 Thread Laura Quinn
I have several large matrices each having perhaps one or two data points missing. For instance one point in 2881 is missing. As I want to perform various analyses on these matrices I feel it is not unreasonable to linearly interpolate over the missing points. I want to basically fill in the gaps

Re: [R] apply/looping query

2004-06-16 Thread Barry Rowlingson
Laura Quinn wrote: x=1:2881 my.new.matrix-matrix(nrow=2881,ncol=20) for(i in 1:20){ my.new.matrix[[i]]-approx(x,my.matrix[,i],n=2881) } the error message says: Error: more elements supplied than there are to replace where am I going wrong?? approx() returns a list with $x and $y components I'd use

[R] Apply a function to each cell of a ragged matrix

2004-02-17 Thread XIAO LIU
R-Helpers: There are a matrix x and a factor f. nrow(x) == length(f), e.g.: x - matrix(1:6, nrow = 3) f - factor(c(daytime, daytime, night)) I want the sum of all elements of rows of x for each corresponding level in factor f, In this case, I want output like: daytime [1]

RE: [R] Apply a function to each cell of a ragged matrix

2004-02-17 Thread Gabor Grothendieck
rowsum(x,f) --- Date: Tue, 17 Feb 2004 17:38:46 -0500 From: XIAO LIU [EMAIL PROTECTED] To: R Help [EMAIL PROTECTED] Subject: [R] Apply a function to each cell of a ragged matrix R-Helpers: There are a matrix x and a factor f. nrow(x) == length(f), e.g.: x - matrix(1:6, nrow = 3

Re: [R] Apply a function to each cell of a ragged matrix

2004-02-17 Thread Mahmoud K. Okasha
Subject: [R] Apply a function to each cell of a ragged matrix R-Helpers: There are a matrix x and a factor f. nrow(x) == length(f), e.g.: x - matrix(1:6, nrow = 3) f - factor(c(daytime, daytime, night)) I want the sum of all elements of rows of x for each corresponding level in factor f

RE: [R] Apply a function to each cell of a ragged matrix

2004-02-17 Thread Liaw, Andy
sapply(split(x,f), sum) daytime night 12 9 HTH, Andy From: XIAO LIU R-Helpers: There are a matrix x and a factor f. nrow(x) == length(f), e.g.: x - matrix(1:6, nrow = 3) f - factor(c(daytime, daytime, night)) I want the sum of all elements of rows of x for each

RE: [R] Apply a function to each cell of a ragged matrix

2004-02-17 Thread Gabor Grothendieck
] Apply a function to each cell of a ragged matrix rowsum(x,f) --- Date: Tue, 17 Feb 2004 17:38:46 -0500 From: XIAO LIU [EMAIL PROTECTED] To: R Help [EMAIL PROTECTED] Subject: [R] Apply a function to each cell of a ragged matrix R-Helpers: There are a matrix x and a factor f. nrow(x

RE: [R] apply to multiple arrays simultaneously

2004-01-09 Thread Liaw, Andy
Off the top of my head, seems like you can abind() the two together and then run apply. See the abind package on CRAN. HTH, Andy From: Carlos Soares Dear R users, Suppose two arrays which partly have the same dimensions. For instance, a1 and a2 with dim(a1) is c(3,4,5,6) and dim(a2)

  1   2   >