Re: [R] Using apply with more than one matrix

2014-05-01 Thread William Dunlap
t; From: arun [mailto:smartpink...@yahoo.com] >> Sent: Thursday, May 01, 2014 6:24 AM >> To: R. Help >> Cc: Waichler, Scott R >> Subject: Re: [R] Using apply with more than one matrix >> >> Hi, >> Sorry, a typo in the previous function: >> -

Re: [R] Using apply with more than one matrix

2014-05-01 Thread Waichler, Scott R
and how I can bring in the operation on a1.  This doesn't > work: > > evaluate <- function(idx) { >   ind.not.na <- which(!is.na(a1[idx,])) ]))  # doesn't work; improper > indexing for a1 >   if(length(ind.not.na) > 0) { >     return(condition1*(a1[idx,ind.

Re: [R] Using apply with more than one matrix

2014-05-01 Thread Waichler, Scott R
> > Sapply or mapply may work, I haven't used these much and will try to > learn better how to use them. Your use of sapply looks good; but I'm > trying to understand if and how I can bring in the operation on a1. This > doesn't work: > > > > evaluate <- function(idx) { > > ind.not.na <- which(!

Re: [R] Using apply with more than one matrix

2014-05-01 Thread arun
ing for a1   if(length(ind.not.na) > 0) {     return(condition1*(a1[idx,ind.not.na[1]] + m2[idx]))  # doesn't work; improper indexing for a1   } } vec <- sapply(seq(length(m2)), evaluate) Scott Waichler > -Original Message----- > From: David Winsemius [mailto:dwinsem...@comcas

Re: [R] Using apply with more than one matrix

2014-05-01 Thread arun
] + m2[idx]))  # doesn't work; improper indexing for a1   } } vec <- sapply(seq(length(m2)), evaluate) Scott Waichler > -Original Message- > From: David Winsemius [mailto:dwinsem...@comcast.net] > Sent: Wednesday, April 30, 2014 8:46 PM > To: Waichler, Scott R > Cc: Bert Gunt

Re: [R] Using apply with more than one matrix

2014-04-30 Thread David Winsemius
Scott Waichler > >> -----Original Message- >> From: David Winsemius [mailto:dwinsem...@comcast.net] >> Sent: Wednesday, April 30, 2014 8:46 PM >> To: Waichler, Scott R >> Cc: Bert Gunter; r-help@r-project.org >> Subject: Re: [R] Using apply with more th

Re: [R] Using apply with more than one matrix

2014-04-30 Thread Waichler, Scott R
Sent: Wednesday, April 30, 2014 8:46 PM > To: Waichler, Scott R > Cc: Bert Gunter; r-help@r-project.org > Subject: Re: [R] Using apply with more than one matrix > > > On Apr 30, 2014, at 6:03 PM, Waichler, Scott R wrote: > > > Here is a working example with no random parts.

Re: [R] Using apply with more than one matrix

2014-04-30 Thread David Winsemius
On Apr 30, 2014, at 6:03 PM, Waichler, Scott R wrote: > Here is a working example with no random parts. Thanks for your patience and > if I'm still off the mark with my presentation I'll drop the matter. > > v <- c(NA, 1.5, NA, NA, > NA, 1.1, 0.5, NA, > NA, 1.3, 0.4, 0.9) > a1 <-

Re: [R] Using apply with more than one matrix

2014-04-30 Thread Richard M. Heiberger
Try ?mapply Description: 'mapply' is a multivariate version of 'sapply'. 'mapply' applies 'FUN' to the first elements of each ... argument, the second elements, the third elements, and so on. Arguments are recycled if necessary. Rich On Wed, Apr 30, 2014 at 9:03 PM, Waich

Re: [R] Using apply with more than one matrix

2014-04-30 Thread Waichler, Scott R
Here is a working example with no random parts. Thanks for your patience and if I'm still off the mark with my presentation I'll drop the matter. v <- c(NA, 1.5, NA, NA, NA, 1.1, 0.5, NA, NA, 1.3, 0.4, 0.9) a1 <- array(v, dim=c(2,2,3)) m1 <- matrix(c(NA, 1.5, 2.1, NA), ncol=2, by

Re: [R] Using apply with more than one matrix

2014-04-30 Thread David Winsemius
etter test might be to specify set.seed() to give a reproducible example. -- David. > > Scott Waichler > > > >> -Original Message- >> From: Bert Gunter [mailto:gunter.ber...@gene.com] >> Sent: Wednesday, April 30, 2014 12:18 PM >> To: Waichl

Re: [R] Using apply with more than one matrix

2014-04-30 Thread Waichler, Scott R
n1[i,j] && length(ind.not.na) > 0) { ans[i,j] <- a1[i,j,ind.not.na[1]] + m2[i,j] } } } Scott Waichler > -Original Message- > From: Bert Gunter [mailto:gunter.ber...@gene.com] > Sent: Wednesday, April 30, 2014 12:18 PM > To: Waichler, Scott R > Cc: r-he

Re: [R] Using apply with more than one matrix

2014-04-30 Thread Bert Gunter
Scott: Your problem specification is rather vague: What do you mean by "use"? In general, matrices are merely vectors with a dim attribute, so if you can do what you want with them as vectors, then that will work for them as matrices. For example: > m1<- matrix(1:6, nr=3) > m2 <- matrix(11:16, n

Re: [R] Using apply with more than one matrix

2014-04-30 Thread Ranjan Maitra
Hi Scott, You could set up a three-dimensional array and then use apply on the desired dimension (MARGIN in apply language). HTH! Many thanks, Ranjan On Wed, 30 Apr 2014 17:54:48 + "Waichler, Scott R" wrote: > Hi, > > I want to apply a custom function to all the elements of one matrix.