similar to: Avoiding a loop

Displaying 20 results from an estimated 7000 matches similar to: "Avoiding a loop"

2007 May 04
2
Alternatives to unlist()
Given the following, one of the things I am trying to see is what % of draws are below a certain number: lambda <- 3 rate <- 5 n <- 5 set.seed(123) v <- replicate(n, rexp(rpois(1,lambda), rate)) vv <- unlist(v) cat("% of draws below 0.1:", round(length(subset(vv, vv < 0.1))/length(vv)*100,0), "%\n") In actuality, my lambda, rate, and n are 26, 10, 1000000,
2005 Nov 30
1
RNG stuck via Fortran call
Having not much success with my previous question I try to reformulate it: I'm simulating a Markow chain in Fortran interfaced with R. Each loop of my Fortran calls various functions of the R RNG through the wrapper given below. In a run of 100 iterations of the Markov kernel, after 20 iterations, the RNG seems like frozen. For example, the first call to the RNG in my loop is:
2010 May 24
2
adding one line to a plot
Hello! I am running a very simple mini Monte-Carlo below using the function tstatistic (right below this sentence): tstatistic = function(x,y){ m=length(x) n=length(y) sp=sqrt( ((m-1)*sd(x)^2 + (n-1)*sd(y)^2)/(m+n-2) ) t=(mean(x)-mean(y))/(sp*sqrt(1/m+1/n)) return(t) } alpha=.1; m=10; n=10 # sets alpha, m, n - for run 1 N=10000 # sets the number of simulations n.reject=0 # counter of num.
2006 Feb 03
2
Problems with ks.test
Hi everybody, while performing ks.test for a standard exponential distribution on samples of dimension 2500, generated everytime as new, i had this strange behaviour: >data<-rexp(2500,0.4) >ks.test(data,"pexp",0.4) One-sample Kolmogorov-Smirnov test data: data D = 0.0147, p-value = 0.6549 alternative hypothesis: two.sided >data<-rexp(2500,0.4)
1999 Aug 30
1
rexp and rweibull
In splus rexp() and rweibull() are related: > set.seed(153) > rexp(1) [1] 0.0493267 > set.seed(153) > rweibull(1, shape=1) [1] 0.0493267 (you can also try shape =2, then rweibull = sqrt(rexp) ) However, in rw0.64.1 (on Win NT) they are different > .Random.seed <- 1:4 > rexp(1) [1] 1.412030 > .Random.seed <- 1:4 > rweibull(1, shape=1) [1] 2.054032 May be rweibull
2007 Jun 21
1
Distance function
Hello you all from the R Help mailing list! I am working on a PowerBook with Mac Os X and use R 2.5.0. I used the distance function from the analogue package to perform a similarity analysis using the Gowers Index and weighted Variables. My variables are bivariate data and measurements as well as interval data transformed into minimum and maximum variables. I used this Code:
2006 Aug 15
1
rexp question
I am using rexp to generate several exponential distributions. I am passing rexp a vector of rates , r. I am wanting to simulate a sample of size 200 for each rate so the code looks like: rexp(n=200*length(r),rate=r) this gives me a vector of the random exponential variables, but they are all disjointed b/c rexp goes through and simulates an exponential variable for each rate and it does that 200
2017 Oct 27
2
How to do a "Box's M" Test with
Trying to get past a frustrating error to do a "simple" Box's M test using Java. The Box's M test says it will work with a data.frame. Here's the setup code: REXP myDf = REXP.createDataFrame(new RList( new REXP[] { new REXPDouble(d1), new REXPDouble(d2), new REXPDouble(d3), new REXPDouble(d4), new REXPInteger(d5) })); Here's the call: REXP boxMResult =
2009 Sep 20
1
Return a list from a .Call but segfaults
Hello, I call a function via .Call passing to it a raw vector(D) and an integer(I) The vector is a series K1,KData1, V1,VData1, K2, KData2, ... where the integer K1 is the length of Data1 and similarly for Ki (wrt Datai)(similarly for V*) There 2*I such pairs( (Ki,KDatai), (Vi,VDatai)) The numbers Ki(and Vi) are written in network order. I am returning a list of I elements each element a
2008 Jul 31
5
Random number generation
Hi Everyone, I did a quick search of the list and it looks like this may not have been asked before... I'm trying to generate a matrix of random numbers between 0 and 1, with 6 columns, 10000 rows. About all I know is that runif(1) gives me the random number I'm looking for. Any help would be great! thanks, -Max
2008 Jul 31
5
Random number generation
Hi Everyone, I did a quick search of the list and it looks like this may not have been asked before... I'm trying to generate a matrix of random numbers between 0 and 1, with 6 columns, 10000 rows. About all I know is that runif(1) gives me the random number I'm looking for. Any help would be great! thanks, -Max
2012 Jan 27
3
generate a random number with rexp ?
dear list I use runif to generate a ramdom number between min and max runif(n, min=0, max=1) however , the syntaxe of rexp does not allow that rexp(n, rate = 1) and it generate a number with the corresponding rate. The question is: how to generate a number between min and max using rexp(). Regards -- PhD candidate in Computer Science Address 3 avenue lamine, cité ezzahra, Sousse 4000
2008 Feb 29
1
patch for random.c
Dear all, while looking for some inspiration of how to organise some code, I studied the code of random.c and noticed that for distributions with 2 or 3 parameters the user is not warned if NAs are created while such a warning is issued for distributions with 1 parameter. E.g: R version 2.7.0 Under development (unstable) (2008-02-29 r44639) [...] > rexp(2, rate=Inf) [1] NaN NaN Warning
2014 Jan 17
1
rexp, different results on 32/64 bit
Hi all, I just run into this today. Apparently rexp() sometimes gives different slightly results for the same seed on 32 bit and 64 bit machines. runif() is the same for both, so the problem seems to be in rexp(). 64 bit Linux is the same as 64 bit OSX, and R-devel gives the same results as R-3.0.2. Best, Gabor # --------------------------------------------- > options(digits=22) ;
2011 Aug 17
3
How to apply a function to subsets of a data frame *and* obtain a data frame again?
Dear all, First, let's create some data to play around: set.seed(1) (df <- data.frame(Group=rep(c("Group1","Group2","Group3"), each=10), Value=c(rexp(10, 1), rexp(10, 4), rexp(10, 10)))[sample(1:30,30),]) ## Now we need the empirical distribution function: edf <- function(x) ecdf(x)(x) # empirical distribution function evaluated at x ##
2015 Apr 09
2
[LLVMdev] BNF for IL/IR interpreter
This might be a very beginner question, but I'm looking for an example for something that I have never done. Suppose that I wanted to express actions with respect to lifted semantics of CPU instructions to an intermediate representation, BAP IL or LLVM IR. How might I go about providing a Backus Naur Form specification and then dynamically interpreting those lifted instructions by also
2008 Jun 09
3
Overlaying the matrices
Hi R, I have a matrix, > x1=matrix(NA,6,6,dimnames=list(letters[1:6],LETTERS[1:6])) > x1 A B C D E F a NA NA NA NA NA NA b NA NA NA NA NA NA c NA NA NA NA NA NA d NA NA NA NA NA NA e NA NA NA NA NA NA f NA NA NA NA NA NA > x2=matrix(rpois(9,1),3,3,dimnames=list(c("b","a","f"),c("D","E","F"))) > x2
2012 Jun 30
2
incorrect number of subscripts on matrix
Hi, Wondering if anyone could help me out with this error.Im trying to fill a matrix with random numbers taken from an exponential distribution using a loop: x.3<-matrix(rep(0,3000),nrow=1000,byrow=T)for(i in 1:1000){x[i,]<-rexp(3,rate=2/3)} I get the error message: Error in x[i, ] <- rexp(3, rate = 2/3) : incorrect number of subscripts on matrix Any ideas??? Appreciate any thoughts.
2009 Mar 17
3
R does not compile any more on FreeBSD 8.0-CURRENT
On a recent FreeBSD 8.0-CURRENT (i386) building R (any version) breaks with the following messages: ---------------------------------------------------------------------- [...snip...] gcc -std=gnu99 -I. -I../../src/include -I../../src/include -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c wilcox.c -o wilcox.o gcc -std=gnu99 -I. -I../../src/include -I../../src/include -I/usr/local/include
2007 May 17
2
controling the size of vectors in a matrix
hie R users l have the following matrix n=20 m<-matrix(nrow=n,ncol=4) colnames(m)=c("treatmentgrp","strata","survivalTime") for(i in 1:n) m[i,]<-c(sample(c(1,2),1,replace=TRUE),sample(c(1:2),1,replace=TRUE),rexp(1,0.07),rexp(1,0.02))