search for: ncol

Displaying 20 results from an estimated 5080 matches for "ncol".

Did you mean: col
2011 May 19
3
problem with optim()
Dear R-users, I would like to maximize the function g above which depends on 4 parameters (2 vectors, 1 real number, and 1 matrix) using optim() and BFGS method. Here is my code: # fonction to maximize g=function(x) { x1 = x[1:ncol(X)] x2 = x[(ncol(X)+1)] x3 = matrix(x[(ncol(X)+2):(ncol(X)+1+ncol(X)*ncol(Y))],nrow=ncol(X),ncol=ncol(Y)) x4 = x[(ncol(X)+1+ncol(X)*ncol(Y)+1):length(x)] res1=rep(0,nrow(X)) res2=matrix(0,nrow=nrow(X),ncol=ncol(Y)) log.res2=matrix(0,nrow=nrow(X),ncol=ncol(Y)) res2.b=rep(0,nrow(X)) res3 = rep(0,nrow...
2010 Apr 09
0
step function
Hello I am using the step function in order to do backward selection for a linear model of 52 variables with the following commands: object<-lm(vars[,1] ~ (vars[,2:(ncol(predictors)+1)]-1)) BackS<-step(object,direction="backward") but it isn't dropping any if the variables in the model, but there are lots of not significant variables as you can see here > object<-lm(vars[,1] ~ (vars[,2:(ncol(predictors)+1)]-1)) > summary(object) Call: lm...
2012 Feb 17
2
(subscript) logical subscript too long in using apply
Dear ALL I have this function in R: func_LN <- function(data){ med_ge <- matrix(c(rep(NA,nrow(data)*ncol(data))), nrow = nrow(data), ncol=ncol(data), byrow=TRUE) T <- matrix(c(rep(NA,length(n)*ncol(data))), nrow = length(n), ncol=ncol(data), byrow=TRUE) Tdiff<- matrix(c(rep(NA,length(n)*ncol(data))), nrow = length(n), ncol=ncol(data), byrow=TRUE) T1<- c(rep(NA,ncol(data))) T0<- c(rep(NA,nc...
2008 Apr 05
2
Adding a Matrix Exponentiation Operator
...by squaring. Is there a way to cut down on the number of copies I am making here (I am assuming that the lhs and rhs of matprod() must be different instances). Any feedback appreciated ! Thanks Rory <snip> /* Convenience function */ static void copyMatrixData(SEXP a, SEXP b, int nrows, int ncols, int mode) { for (int i=0; i < ncols; ++i) for (int j=0; j < nrows; ++j) REAL(b)[i * nrows + j] = REAL(a)[i * nrows + j]; } SEXP do_matexp(SEXP call, SEXP op, SEXP args, SEXP rho) { int nrows, ncols; SEXP matrix, tmp, dims, dims2; SEXP x, y, x_, x__; int i,j,...
2010 Nov 10
2
Parallel code runs slower!
My parallel code is running slower than my non-parallel code! Can someone pls advise what am I doing wrong here? t and tTA are simple matrices of equal dimensions. #NON PARALLEL CODE nCols=ncol(t) nRows=nrow(t) tTA = matrix(nrow=nRows,ncol=nCols) require(TTR) system.time( for (i in 1:nCols) { x = t[,i] xROC = ROC(x) tTA[,i]=xROC } ) user system elapsed 123.24 0.07 123.47 # PARALLEL CODE nCols=ncol(t) nRows=nrow(t) tTA = matrix(nrow=nRows,ncol=nCols) require(do...
2013 Feb 07
1
Merging data in arrays
Dear All, Here is a hypothetical sample (sorry for the clumsy code): A1 <- matrix(1:5, nrow=5, ncol=1) A2 <- matrix(6:10, nrow=5, ncol=1) A3 <- matrix(11:15, nrow=5, ncol=1) A4 <- matrix(16:20, nrow=5, ncol=1) A5 <- matrix(21:25, nrow=5, ncol=1) A6 <- matrix(26:30, nrow=5, ncol=1) B1 <- matrix(c(A1, A2, A3), nrow=5, ncol=3) B2 <- matrix(c(A2, A3, A4), nrow=5, ncol=3) B3 <...
2012 Dec 08
5
How to efficiently compare each row in a matrix with each row in another matrix?
...and B. They have the same number of columns but possibly different number of rows. I would like to compare each row of A with each row of B and check whether all entries in a row of A are less than or equal to all entries in a row of B. Here is a minimal working example: A <- rbind(matrix(1:4, ncol=2, byrow=TRUE), c(6, 2)) # (3, 2) matrix B <- matrix(1:10, ncol=2) # (5, 2) matrix ( ind <- apply(B, 1, function(b) apply(A, 1, function(a) all(a <= b))) ) # (3, 5) = (nrow(A), nrow(B)) matrix The question is: How can this be implemented more efficiently in R, that is, in a faster way? T...
2010 Oct 13
1
(no subject)
Dear all, I have just sent an email with my problem, but I think no one can see the red part, beacuse it is black. So, i am writing again the codes: rm(list=ls()) #remove almost everything in the memory set.seed(180185) nsim <- 10 mresultx <- matrix(-99, nrow=1000, ncol=nsim) mresultb <- matrix(-99, nrow=1000, ncol=nsim) N <- 200 I <- 5 taus <- c(0.480:0.520) h <- c(1:20/1000) alpha1 <- c(1:82) aeven1 <- alpha[2 * 1:41] aodd1 <- alpha[-2 * 1:41] alpha2 <- c(1:40) aeven2 <- alpha2[2 * 1:20] #Create an object to hold results. M <- ma...
2009 Apr 05
2
loop problem for extract coefficients
...s. I have performed a Elastic Net regression and I want to store the coeffcients in each iteration. I got an error message . I do not know where is the problem???? Please help me. Thanks *Code:* ------------------------------------------------------- library(elasticnet) X<-matrix(rnorm(200),ncol=20) Y<-matrix(rnorm(200),ncol=20) loop <- 20 size <- 20 enres<-matrix(nrow = size, ncol = loop) fit<-matrix(nrow = size, ncol = loop) store<-matrix(nrow = size, ncol = loop) for(j in 1: 10) print (paste(j,"/200",sep="")) { enres<-enet(x=X,y=Y[,j],lambda=1,no...
2010 Mar 27
1
R runs in a usual way, but simulations are not performed
...yours, Martin Bo?a (Matej Bel University / Faculty of Natural Sciences / Bansk? Bystrica / Slovakia). # zav?dza s?riu podporn?ch funkci? # zav?dza trace, sigma, fi, xs, xs, fixs, sxfixs tr <- function(M) sum(diag(M)) sigma_ADD <- function(alpha) diag(as.vector(alpha %*% t(z)), nrow=nrow(z), ncol=nrow(z)) sigma_MIX <- function(alpha) diag((as.vector(alpha %*% t(z)))^2, nrow=nrow(z), ncol=nrow(z)) sigma_EXP <- function(alpha) diag(exp(as.vector(alpha %*% t(z))), nrow=nrow(z), ncol=nrow(z)) fi <- function(sigma) solve(crossprod(x, crossprod(solve(sigma),x))) xs <- function(sigma...
2012 Feb 04
1
RFC: Proposal to make NROW() and NCOL() slightly more general
The help has > Description: > 'nrow' and 'ncol' return the number of rows or columns present in 'x'. > 'NCOL' and 'NROW' do the same treating a vector as 1-column matrix. and > x: a vector, array or data frame I'm proposing to extend these two convenience functions to also work ``correctly''...
2010 Oct 13
4
loop
...loop in my codes, but the software returns an error: "subscript out of bounds" I dont understand exactly why this is happenning. My codes are the following: rm(list=ls()) #remove almost everything in the memory set.seed(180185) nsim <- 10 mresultx <- matrix(-99, nrow=1000, ncol=nsim) mresultb <- matrix(-99, nrow=1000, ncol=nsim) N <- 200 I <- 5 taus <- c(0.480:0.520) h <- c(1:20/1000) codd <- c(1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81) ceven <- c(2,4,6,8,10,12,14,16,18,20,22,...
2012 Aug 10
2
Zoo object problem: Find the column name of a univariate zoo object
Hi everyone and Achim, Achim, I appreciate your help about the function "NCOL". When I use "NCOL" instead of "ncol", I can find out the number of columns (number of time series) in the presence of only one time series (one variable, one column). Now I want to know how I can find out the column names of the zoo objects? In case of more than one ti...
2011 Dec 26
4
Other ways to lm() regression? (non-loop?)
...39;m quite new to R (1 month full time use so far). I have to run loop regressions VERY often in my work, so I would appreciate some new methodology that I'm not considering. #--------------------------------------------------------------------------------------------- y<-matrix(rnorm(100),ncol=10,nrow=10) x<-matrix(rnorm(50),ncol=5,nrow=10) #Suppose I want to run the specification y=A+Bx+error, for each and every y[,n] onto each and every x[,n]. #So with: ncol(y);ncol(x) #I should end up with 10*5=50 regressions in total. #I know how to do this fine: MISC1<-0 for(i in 1:ncol(y)){...
2009 Apr 11
2
who happenly read these two paper Mohsen Pourahmadi (biometrika1999, 2000)
....04,-0.26,-0.03,-0.04,-0.05) y5=c(-0.02,-0.34,0.06,-0.22,-0.11,-0.31) y6=c(0.20,0.01,0.01,-0.26,0.01) y7=c(-0.06,-0.14,0.39,0.23) y8=c(0.21,0.10,0.09) y9=c(-0.24,-0.23) y10=c(0.13) y=c(y1,y2,y3,y4,y5,y6,y7,y8,y9,y10) ## autoregressive paramters ,table 1 biometrika 1999,page 685 om2=matrix(0,nrow=55,ncol=3) om1=poly(c(1:10),degree=3) ##polynomial design matirx with level =11,cubic om2[1:10,]=t(matrix(rep(om1[1,],10),ncol=10)) om2[11:19,]=t(matrix(rep(om1[2,],9),ncol=9)) om2[20:27,]=t(matrix(rep(om1[3,],8),ncol=8)) om2[28:34,]=t(matrix(rep(om1[4,],7),ncol=7)) om2[35:40,]=t(matrix(r...
2017 Jul 05
4
expand gridded matrix to higher resolution
...dy? I tried matrix with rep, but I am missing some magic there, since it doesn't do what we need. replicate might be promising, but then still need to rearrange the output into the column and row format we need. A simple example: mm=matrix(1:15,nrow=3,byrow = T) xmm=matrix(NA,nrow=nrow(mm)*3,ncol=ncol(mm)*3) for(icol in 1:ncol(mm)) { for(irow in 1:nrow(mm)) { xicol=(icol-1)*3 +c(1:3) xirow=(irow-1)*3 +c(1:3) xmm[xirow,xicol]=mm[irow,icol] } } mm > > mm > [,1] [,2] [,3] [,4] [,5] > [1,] 1 2 3 4 5 > [2,] 6 7 8 9 10 > [3,] 1...
2009 Jan 07
0
How-To extract data from a matrix of lists subject to a set of given constraints
...a number of time series in such a way to be able to extract subsets satisfying giben conditions. I have defined the following 11 matrices whose x-axis represent time intervals and y-axis represent the number of time series: MS <- 11 d1.mat <- matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-1)) d2.mat <- matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-3)) d3.mat <- matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-3)) d4.mat <- matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-4)) d5.mat <- matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-5))...
2010 Oct 07
3
quantile regression
Dear all, I am a new user in r and I am facing some problems with the quantile regression specification. I have two matrix (mresultb and mresultx) with nrow=1000 and ncol=nsim, where I specify (let's say) nsim=10. Hence, the columns in my matrix represents each simulation of a determined variable. I need to regress each column of mresultb on mresultx. My codes are the following: set.seed(180185) nsim <- 10 mresultx <- matrix(-99, nrow=1000, ncol=nsim)...
2001 Jan 03
1
memory trouble
I don't know whether this belongs to r-devel or rather r-help. Under RW1.11 --nsize=8M --vsize=512M I could n <- 500000 m <- 20 x <- matrix(rnorm(n*m), ncol=m, nrow=n) gc() > n <- 500000 > m <- 20 > x <- matrix(rnorm(n*m), ncol=m, nrow=n) > gc() free total (Mb) Ncells 8190509 8388608 160 Vcells 57033698 67108864 512 # under RW1.20 --vanilla the same fails, some testing shows n <- 500000 m <- 20 x <-...
2012 Dec 11
1
converting manual command to loop command
...ds into a simple loop. Your help is required on it thanks in advance eliza kindly note: "e" is matrix whose each column has to be executed into a distance vector ##To get a distance matrix >a<-dist(e[,1], upper=TRUE, diag=TRUE) ##To convert it in a matrix >a<-matrix(a, ncol=1) >b<-dist(e[,2], upper=TRUE, diag=TRUE) >b<-matrix(b, ncol=1) >c<-dist(e[,3], upper=TRUE, diag=TRUE) >c<-matrix(c, ncol=1) >d<-dist(e[,4], upper=TRUE, diag=TRUE) >d<-matrix(d, ncol=1) >ee<-dist(e[,5], upper=TRUE, diag=TRUE) >ee<-matr...