Arun has given you a number of ways to do what you (seem to) want. If
this is fast enough, then you're done.
If not, then the key to speeding things up is to do things
differently. Note that a 1 x 9 matrix is a just a vector. Since each
element of the vector is a "different computation", apparentl
HI,
May be this helps:
example <- function(X,n){
lst1 <- list()
for(i in 1:n){
cell1 <- sample(X,1)
cell2 <- sample(X,1)
table1 <- cbind(cell1,cell2)
lst1[[i]] <- table1
}
do.call(rbind,lst1)
}
#or
example1 <- function(X,n){
table1 <- vector()
for(i in 1:n){
cell1 <- sample(X,1)
cell2 <- sample
Hi Petr and Jean,
thanks very much, problem solved! Really appreciate your help.
Jennifer
--
View this message in context:
http://r.789695.n4.nabble.com/repeating-a-function-across-a-data-frame-tp4638643p4638678.html
Sent from the R help mailing list archive at Nabble.com.
_
As Petr suggests, the dist() function will do much of the work for you.
For example ...
# example matrix of data
nsamples <- 40
nreadings <- 46
dat <- matrix(runif(nsamples*nreadings), nrow=nsamples)
# Euclidean distance between the ROWS of dat
distance <- dist(dat)
Jean
JenniferH wrote on
Hi
did you find function dist? It seems that it can do directly what you
want.
Regards
Petr
>
> Hello everyone. Like others on this list, I'm new to R, and really not
much
> of a programmer, so please excuse any obtuse questions! I'm trying to
> repeat a function across all possible combina
Hello everyone. Like others on this list, I'm new to R, and really not much
of a programmer, so please excuse any obtuse questions! I'm trying to
repeat a function across all possible combinations of vectors in a data
frame. I'd hugely appreciate any advice!
Here's what I'm doing:
I have some
On 05.07.2011 16:47, Daniel Malter wrote:
Thanks, Uwe, for sending me this the second time.
Daniel,
I do not track names, sorry for posting twice.
> I send my responses through nabble.
Great, so you found the main problem already.
So #1 does not seem to be an option;
It is an option:
Thanks, Uwe, for sending me this the second time. I send my responses through
nabble. So #1 does not seem to be an option; #2 I sometimes forget.
Regards,
Daniel
Uwe Ligges-3 wrote:
>
> On 02.07.2011 20:51, Daniel Malter wrote:
>> You can just tell the function to create 1000 random numbers. Se
On 02.07.2011 20:51, Daniel Malter wrote:
You can just tell the function to create 1000 random numbers. See ?runif for
the specifics. The arguments are n, min, and max. 'n' is the one you are
looking for.
Thanks for providing help on R-help, but for the future please
- respond to the OP rath
If you want to repeat an entire function, use replicate as in
replicate(15,sapply(1,function(x) runif(x)))
Here, sapply(1,function(x) runif(x)) draws on uniformly distributed
variable. replicate(15,...) is the wrapper function that tells to do this 15
times. The benefit here is that you can repli
You can just tell the function to create 1000 random numbers. See ?runif for
the specifics. The arguments are n, min, and max. 'n' is the one you are
looking for.
Da.
--
View this message in context:
http://r.789695.n4.nabble.com/Repeating-a-function-in-R-tp3640508p3640966.html
Sent from the R h
Hi:
The r functions are vectorized, so the loop is unnecessary:
drift <- rbinom(55, 80, 0.4)
or within a function,
drift <- function(p0 = 0.4, N = 40, ngen = 55) rbinom(ngen, 2 * N, p0)
To repeat it 1000 times, you have at least two options:
(1) [1000 columns]
simmat <- replicate(1000, drif
Hi,
try this;
output <- list()
times <- 1000
drift <-function(p0=0.4,N=40,ngen=55){
p = p0
for( i in 1:ngen){
p = rbinom(1,2*N,p)/(2*N)
}
return( p )
}
for(i in 1:times){
result <- drift(0.4, 40, 55)
output <- c(output, list(resu
Hello all,
I currently have this function:
drift <-function(p0=0.4,N=40,ngen=55){
p = p0
for( i in 1:ngen){
p = rbinom(1,2*N,p)/(2*N)
}
return( p )
}
I want to repeat it 1000 times, then do some analysis on the results. I've
tried u
14 matches
Mail list logo