Eekhout, I. wrote on 09/19/2011 10:16:17 AM:
>
> Hi all,
>
> I would like to replace the for loop in the code below with a function
> to improve the speed and to make the script more efficient.
> The loop creates a vector of integers (x) with the probability of f for
> each integer.
> The lengt
sorry, there is a superfluous bracket at the end of the line, it should
be read as
sample(1:3,50,prob=c(0.5,0.15,0.35),replace=T)
Am 19.09.2011 19:08, schrieb Eik Vettorazzi:
> Hi Iris,
> maybe I misinterpret this, but I think in the end it all comes down to
> sample(1:3,50,prob=c(0.5,0.15,0.35),r
Hi Iris,
maybe I misinterpret this, but I think in the end it all comes down to
sample(1:3,50,prob=c(0.5,0.15,0.35),replace=T))
cheers
Am 19.09.2011 17:16, schrieb Eekhout, I.:
> Hi all,
>
> I would like to replace the for loop in the code below with a function
> to improve the speed and to mak
Hi all,
I would like to replace the for loop in the code below with a function
to improve the speed and to make the script more efficient.
The loop creates a vector of integers (x) with the probability of f for
each integer.
The length of f is variable, but sums to 1.
I tried to use a function
Well actually, in that case, I don't think it is really necessary to
replace the loop because it is quite fast with the small size I have.
But I thought it would help me to understand how would vectorization
work and how to use the *apply functions.
Thanks anyway for your piece of advice!
Ivan
Hi
how many objects do you have in a list? Loop is ineffective if you use
several nested loops and/or there is some unnecessary mimic of simple
function.
e.g. you can use this
set.seed(666)
x <- runif(10)
vysled <- 0
for(i in 1:length(x)) {
if(vysled > x[i]) vysled <- vysled else vysled <- x[i
After reading the R news, I've tried this code and it works:
> rapply(list(names(test),test), write.csv, file="filename.csv",
append=T, row.names=F)
However, the output is structured like this:
names(test)[[1]]
names(test)[[2]]
etc...
test[[1]]
test[[2]]
etc...
I would like to alternate names(
On Wed, Feb 10, 2010 at 9:50 AM, Ivan Calandra
wrote:
> I'm still quite new in R and I don't really understand this whole
> "vectorization" thing.
>
See [1] for an article on vectorisation and loops in R.
Liviu
[1] http://www.r-project.org/doc/Rnews/Rnews_2008-1.pdf
_
Hi everybody!
I'm still quite new in R and I don't really understand this whole
"vectorization" thing.
For now, I use a for loop (and it works fine), but I think it would be
useful to replace it.
I want to export the result of a test statistic, which is stored as a
list, into a csv file. I t
Have you considered using a different data structure:
> # change the data structure
> x <- data.frame(
+ type=rep(c('x1', 'x2', 'x3'), each=100),
+ high=c(d[,4], d[,5], d[,6]),
+ value=c(d[,1], d[,2], d[,3]))
> head(x)
type high value
1 x10 0.8936737
2 x10 -1.047298
Dear helpers.
I often need to make dichotomous variables out of continuous ones (yes, I
realize the problems with throwing away much of the information), but I then
like to check the min and max of each category. I have the following simple
code to do this that cuts each variable (x1,x2,x3) at th
11 matches
Mail list logo