[R] Is there a faster way to do this?

2010-03-25 Thread Márcio Resende
Hi guys, I am still learning R, and not well familiar with all the apply functions. I am trying to find faster alternatives to replace the for cycle. Is there a faster way to do the example below? nm <- 1000 b <- matrix (rnorm (5000, 0, 1), nrow = 500, ncol = nm) a <- matrix (0, nm, nm) for (i in

Re: [R] Dimnames of array inside loop

2010-03-18 Thread Márcio Resende
I read the post http://n4.nabble.com/Error-setting-rowname-if-rowname-currently-NULL-td794579.html#a794579 where it says that the problem is that dimnames(acuracia) is Null ->equivalent to rownames(fred) is NULL (in the post) Then I tried to define all the dimnames first as random names to be the

[R] Dimnames of array inside loop

2010-03-15 Thread Márcio Resende
hello R-helpers, I have an array acuracia <- array(NA, dim = c(1, 1, A, B, C)) which is first defined and in the example above with dimensions 1x1xAxBxC. My array is then filled using 3 loops (I am not well familiar yet with lapply or sapply functions so I am still a loop-user): for (i in 1:A)

[R] storing matrix(variables) in loop

2010-03-15 Thread Márcio Resende
Hello R-helpers, I have the following code that works well, b <-list() for (i in 1:3){ a <- matrix(runif(1),3,3) b[[i]] <- a } b however, I need to do something similar with two loops and I was looking for something that would look like b <- list() for (i in 1:3){ for (j in 1:4){ a <- matrix(r

Re: [R] how to track a number in a row

2010-01-11 Thread Márcio Resende
llumn is related to number 1 and the first row, related to row 1 on matrix a Thanks again Márcio Resende wrote: > > Hi, > I have a 100x15 matrix and in each row a set of 15 random numbers out of > 25. > for example: > > b <- c(1:25) > a <-matrix(0,10,15) >

[R] how to track a number in a row

2010-01-11 Thread Márcio Resende
Hi, I have a 100x15 matrix and in each row a set of 15 random numbers out of 25. for example: b <- c(1:25) a <-matrix(0,10,15) for (i in 1:10){ a[i,] <- sample(b,15,replace = FALSE) } I would like to create another matrix (25x100), for example "d" with the probability of each number from the fir

Re: [R] equivalent of ifelse

2009-12-09 Thread Márcio Resende
David Winsemius wrote: > > > On Dec 9, 2009, at 12:40 PM, carol white wrote: > >> Hi, >> Is there any equivalent for ifelse (except if (cond) expr1 else >> expr2) which takes an atomic element as argument but returns vector >> since ifelse returns an object of the same length as its argum

[R] Assign variables in a loop to a list

2009-12-09 Thread Márcio Resende
Dear R helpers, I am new in R and I am having trouble with a function. I am proggraming a genetic analysis and there is a script that generates a lot of different matrix, for example x,y and z. And what I am trying to do is to loop the same script for different variables the user will define in th

[R] Using two (...) in a function

2009-12-01 Thread Márcio Resende
Hello R-Helpers, I am not sure if it is a very simple question but I would like to use two (...) in a function, for example, this is a script where I would like to input the variable names (in one of the (...)) and the variances associated to those variables which are not calculated in the script