dear all,
consider a simple function like
func = function(){ return(runif()) }
and say that you would like to create a vector of size N, each entry being a
call to this function "func". What is the equivalent of the python
code
vect = [ func() for i in range(N)]
Indeed, you cannot just call vect<-rep( func(), N) - I guess that there
also exists a one-liner to do that in R, doesn't it ?
Sorry for the very basic question!
Best,
Alek
--
View this message in context:
http://r.789695.n4.nabble.com/vector-creation-tp2308840p2308840.html
Sent from the R help mailing list archive at Nabble.com.
alekk wrote:> > consider a simple function like > func = function(){ return(runif()) } > and say that you would like to create a vector of size N, each entry being > a call to this function "func". What is the equivalent of the python code > vect = [ func() for i in range(N)] > Indeed, you cannot just call vect<-rep( func(), N) - I guess that there > also exists a one-liner to do that in R, doesn't it ? >?runif vect <- runif(N) /Berend -- View this message in context: http://r.789695.n4.nabble.com/vector-creation-tp2308840p2308844.html Sent from the R help mailing list archive at Nabble.com.
sorry for being unclear:
my function func() is actually more complicated than that, and uses random
numbers to generate its result. If I run something like
vect = rep(func(), N)
I will get something like (x,x,x, ... ,x).
What is the right way to do that ?
Thanks!
--
View this message in context:
http://r.789695.n4.nabble.com/vector-creation-tp2308840p2308869.html
Sent from the R help mailing list archive at Nabble.com.