similar to: Table to matrix

Displaying 20 results from an estimated 10000 matches similar to: "Table to matrix"

2013 Jan 16
3
matrix manipulation with its rows
Dear R users, I have a question about matrix manipulation with its rows. Plz see the simple example below sample <- list(matrix(1:6, nr=2,nc=3), matrix(7:12, nr=2,nc=3), matrix(13:18,nr=2,nc=3)) > sample [[1]] [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 [[2]] [,1] [,2] [,3] [1,] 7 9 11 [2,] 8 10 12 [[3]] [,1] [,2] [,3] [1,] 13 15 17 [2,]
2013 Jan 17
2
create block diagonal with each rows
Dear R users, I'd like to create a block diagonal matrix with each rows in a matrix. Here is a simple example. (In fact, the matrix is big) x <- matrix(1:20, 4,5) > x [,1] [,2] [,3] [,4] [,5] [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20 With each rows in matrix x, I'd like to make the matrix below.
2010 Apr 16
3
VERY SIMPLE QUESTION
Dear R users, I am looking for more efficient way to compute the followings -------------------------------------------------------------------------- a <- matrix(c(1,1,1,1,2,2,2,2),4,2) b <- matrix(c(1,2,3,4),4,1) Eventually, I want to get this matrix, `c`. c <- matrix(c(1/1,1/2,1/3,1/4,2/1,2/2,2/3,2/4),4,2) --------------------------------------------------------------------------
2009 Jul 28
3
character vector -> numeric matrix ??
Dear R users... I'd like to change this character vector, "zz", zz <- c("12","56","89") to the following numeric matrix. [,1] [,2] [1,] 1 2 [2,] 5 6 [3,] 8 9 Actually, "zz" vector has a long length. Any comments will be greatly appreciated. Kathryn Lord -- View this message in context:
2008 Oct 08
3
Re move repeated values
Dear R users, I'd like to make this data rem.y = c(-1,0,2,4,5) from y = c(-1,-1,0,2,2,2,2,4,4,5,5,5,5,5). That is, I need to remove repeated values. Here is my code, but I don't think it is efficient. How could I improve this? #------------------------------------------------------------------------ y = c(-1,-1,0,2,2,2,2,4,4,5,5,5,5,5) n=length(y) for (i in 1:n) #
2011 Aug 11
5
generate two sets of random numbers that are correlated
Dear R users I'd like to generate two sets of random numbers with a fixed correlation coefficient, say .4, using R. Any suggestion will be greatly appreciated. Regards, Kathryn Lord -- View this message in context: http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-correlated-tp3735695p3735695.html Sent from the R help mailing list archive at Nabble.com.
2009 Jul 27
2
Splitting matrix into several small matrices
Dear R users... I need to split this matrix(or dataframe), for example, z <- matrix(c(13,1,1,1,1,12,0,0,0,0,8,1,0,1,1,8,0,1,0,0, 10,1,1,1,1,3,0,1,0,0,3,1,0,1,1,6,1,1,1,1),8,5,byrow = T) > z [,1] [,2] [,3] [,4] [,5] [1,] 13 1 1 1 1 [2,] 12 0 0 0 0 [3,] 8 1 0 1 1 [4,] 9 0 1 0 0 [5,] 10 1 1 1 1
2008 Nov 17
2
re sults from "do.call" function
Dear R users... I made this by help of one of R users. _________________________________________________________________ X=matrix(seq(1,4), 2 , 2) B=matrix(c(0.6,1.0,2.5,1.5) , 2 , 2) func <- function(i,y0,j) { y0*exp(X[i,]%*%B[,j]) } list1 <- expand.grid( i=c(1,2) , y0=c(1,2) , j=c(1,2) ) results <- do.call( func , list1 )
2009 Aug 22
1
computation of matrices in list of list
Dear R users, I have the list as follows; #------------------------------------------------------ > z [[1]] [[1]][[1]] matrix(A) [[1]][[2]] matrix(B) [[1]][[3]] matrix(C) [[2]] [[2]][[1]] matrix(D) [[2]][[2]] matrix(E) [[2]][[3]] matrix(F) #--------------------------------------------- I'd like to compute matrix(A)+matrix(B)+matrix(C)+matrix(D)+matrix(E)+matrix(F) In
2009 Aug 27
1
ignore an error and go back to ....
Dear R users, is there way to ignore an error and go back to 1st line? I mean, #------------------------------- while (or repeat) ------------ { 1 2 . . . 6 } #----------------------------- For example, if I have an error in the 6th line, then I'd like to go back to the 1st line. I've already tried "try", but it didn't work. Any suggestion will be greatly
2011 Aug 03
1
create a list under constraints
Hi, R users, Here is an example. k <- c(1,2,3,4,5) i <- c(0,1,3,2,1) if k=1, then i=0 if k=2, then i=0, 1 if k=3, then i=0, 1, 2, 3 if k=4, then i=0, 1, 2 if k=5, then i=0, 1 so i'd like to create a list like below. > list k i 1 1 0 2 2 0 3 2 1 4 3 0 5 3 1 6 3 2 7 3 3 8 4 0 9 4 1 10 4 2 11 5 0 12 5 1 I tried expand.grid, but I can't. Any suggestion will be
2008 Aug 29
1
more efficient double summation...
Dear R users... I made the R-code for this double summation computation http://www.nabble.com/file/p19213599/doublesum.jpg ------------------------------------------------- Here is my code.. sum(sapply(1:m, function(k){sum(sapply(1:m, function(j){x[k]*x[j]*dnorm((mu[j]+mu[k])/sqrt(sig[k]+sig[j]))/sqrt(sig[k]+sig[j])}))})) ------------------------------------------------- In fact, this is
2011 Aug 02
1
My R code is not efficient
Dear R users, I have two n*1 integer vectors, y1 and y2, where n is very very large. I'd like to compute elbp = 4^(y1) * 5^(y2) * sum_{i=0}^{max(y1, y2)} [{ (y1-i)! * (i)! * (y2-i)! }^(-1)]; that is, I need to compute "elbp" for each (y1, y2) pair. So I made R code like below, but I don't think it's efficient Would you plz tell me how to avoid this "for"
2011 Aug 29
3
gradient function in OPTIMX
Dear R users When I use OPTIM with BFGS, I've got a significant result without an error message. However, when I use OPTIMX with BFGS( or spg), I've got the following an error message. ---------------------------------------------------------------------------------------------------- > optimx(par=theta0, fn=obj.fy, gr=gr.fy, method="BFGS", >
2009 Aug 20
1
how to compute this summation...
Dear R users, I try to compute this summation, http://www.nabble.com/file/p25054272/dd.jpg where f(y|x) = Negative Binomial(y, mu=exp(x' beta), size=1/alp) http://www.nabble.com/file/p25054272/aa.jpg http://www.nabble.com/file/p25054272/cc.jpg In fact, I tried to use "do.call" function to compute each u(y,x) before the summation, but I got an error, "Error in X[i, ]
2010 Aug 04
2
discrete ECDF
Dear list; I just created a utility function that replicates what I have done in the past with Excel or OO.org by putting a formula of the form =sum($A1:A$1) in an upper-corner of a section and then doing a "fill" procedure by dragging the lower-rt corner down and to the right. When divided by the grand sum of the entries this function then calculates a 2D-discrete-ECDF. I
2011 Aug 13
3
optimization problems
Dear R users I am trying to use OPTIMX(OPTIM) for nonlinear optimization. There is no error in my code but the results are so weird (see below). When I ran via OPTIM, the results are that Initial values are that theta0 = 0.6 1.6 0.6 1.6 0.7. (In fact true vales are 0.5,1.0,0.8,1.2, 0.6.) -------------------------------------------------------------------------------------------- >
2015 Jun 30
3
Loop for: mostrar el nombre de la variables
Buenos días: Después de más de 20 años en SAS, ahora igual me toca trabajar en R. Y la transición es muy dura: la "lógica" de los dos lenguajes es, para mi, totalmente diferente. Disculpen si lo que pregunto es una obviedad, pero llevo todo el día con esto y no logro encontrar la respuesta adecuada con google. Estoy intentado crear una función que realice una descriptiva simple de
2008 Feb 20
3
reshaping data frame
Dear all, I'm having a few problems trying to reshape a data frame. I tried with reshape{stats} and melt{reshape} but I was missing something. Any help is very welcome. Please find details below: ################################# # data in its original shape: indiv <- rep(c("A","B"),c(10,10)) level.1 <- rpois(20, lambda=3) covar.1 <- rlnorm(20, 3, 1) level.2
2010 Jan 07
1
faster GLS code
Dear helpers, I wrote a code which estimates a multi-equation model with generalized least squares (GLS). I can use GLS because I know the covariance matrix of the residuals a priori. However, it is a bit slow and I wonder if anybody would be able to point out a way to make it faster (it is part of a bigger code and needs to run several times). Any suggestion would be greatly appreciated. Carlo