search for: nrow

Displaying 20 results from an estimated 6334 matches for "nrow".

Did you mean: now
2010 Dec 24
3
selection of outputs from the function
Hi Dear All, This is a function which contains Covariance Ratio and Likelihood Distance values (CVRi, LDi). i want to compute the all row's values, that is run this function for nrow(X) times. The X and Y matrices are; X<-matrix(c(1125,920,835,1000,1150,990,840,650,640,583,570,570,510,555,460,275,510,165,244,79,232,268,271,237,192,202,184,200,180,165,151,171,243,147,286,198,196,210,327,334,7160,8804,8108,6370,6441,5154,5896,5336,5041,5012,4825,4391,4320,3709,3969,3558,4361,...
2011 May 19
3
problem with optim()
...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(X)) res3.b = rep(0,nrow(X)) for (i in 1:nrow(X)) { res1[i]=1/(1+exp(-t(x1)%*%X[i,]-...
2013 Sep 02
3
Product of certain rows in a matrix
Hi, You could try: A<- matrix(unlist(read.table(text=" 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 ",sep="",header=FALSE)),ncol=3,byrow=FALSE,dimnames=NULL) library(matrixStats) ?res1<-t(sapply(split(as.data.frame(A),as.numeric(gl(nrow(A),2,6))),colProds)) ?res1 #? [,1] [,2] [,3] #1??? 4?? 10?? 18 #2?? 63?? 64?? 63 #3?? 18?? 10??? 4 ?res2<-t(sapply(split(as.data.frame(A),((seq_len(nrow(A))-1)%/%2)+1),colProds)) ?identical(res1,res2) #[1] TRUE #or ?t(sapply(split(as.data.frame(A),as.numeric(gl(nrow(A),2,6))),function(x) app...
2012 Oct 08
1
Any better way of optimizing time for calculating distances in the mentioned scenario??
...dealing with a case, where 'manhattan' distance of each of 100 vectors is calculated from 10000 other vectors. For achieving this, following 4 scenarios are tested: 1) scenario 1: > x<-read.table("query.vec") > v<-read.table("query.vec2") > d<-matrix(nrow=nrow(v),ncol=nrow(x)) > for (i in 1:nrow(v)){ + d[i,]<- sapply(1:nrow(x),function(z){dist(rbind(v[i,],x[z,]),method="manhattan")}) + } > print(d[1,1:10]) time taken for running the code is : real 1m33.088s user 1m32.287s sys 0m0.036s 2) scenario2: > x<-read.table(&qu...
2009 Apr 14
1
mean fold change issues and p values
...gth(sig_test) if(len_sig_test%%2 > 0) message("Number of groups for t-test is not paired.") if(max(sig_test) > group) message("Group number for t-test is out of range.") data.norm.test = data.norm.zo #normalized data nrow <- nrow(data.norm.test) ncol <- ncol(data.norm.test) p.ttest = rep(NA, nrow) #parametric test -- t test p.wilcox = rep(NA, nrow) #non-parametric test -- Mann-Whitney test fold.mean <- rep(NA, nrow) mean.na...
2010 Jul 25
0
Redefine NROW and NCOL to be compatible with nrow and ncol for S3 classes with own dim function?
Dear R-developers, I am currently trying to develop a package with some customized container classes and found an issue with the functions NROW and NCOL. I guess that I can simply work around the problem by redefining these functions in my own package (Yet, I do not know whether that will work cleanly everywhere). Nevertheless, I thought that perhaps one might think about to redefine these functions in the base package. As example con...
2008 Apr 05
2
Adding a Matrix Exponentiation Operator
...nentiation 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__;...
2009 May 26
1
Bug in "$<-.data.frame" yields corrupt data frame (PR#13724)
Full_Name: Steven McKinney Version: 2.9.0 OS: Mac OS X 10.5.6 Submission from: (NULL) (142.103.207.10) A corrupt data frame can be constructed as follows: foo <- matrix(1:12, nrow = 3) bar <- data.frame(foo) bar$NewCol <- foo[foo[, 1] == 4, 4] bar lapply(bar, length) > foo <- matrix(1:12, nrow = 3) > bar <- data.frame(foo) > bar$NewCol <- foo[foo[, 1] == 4, 4] bar X1 X2 X3 X4 NewCol 1 1 4 7 10 <NA> 2 2 5 8 11 <NA> 3 3...
2006 Oct 23
2
getting the by() function to work properly
...#39;d be glad to give more if its needed. I would really appreciate any suggestions at all. Thanks in advance. f3=function(x) { + + twodied=x[died==2,]; + twosaved=x[saved==2,]; + hit2=x[saved==2 & choice=="+",]; + fa2=x [died==2 & choice=="+",]; d2=(qnorm(((nrow(hit2))/(nrow(twosaved))))-qnorm((nrow(fa2))/(nrow(twodied)))); + hitrate=((nrow(hit2))/(nrow(twosaved))); FArate=((nrow(fa2))/(nrow(twodied))); + zhit2=qnorm(((nrow(hit2))/(nrow(twosaved))));zfa2=qnorm((nrow(fa2))/(nrow(twodied)));B2= -.5*(zhit2+zfa2); + tp2=mean(twosaved$resp); + ta2=mean(two...
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)...
2009 Aug 10
3
how use cat() function?
...cyClass3 =3              i have do it like this:!!! data1 <- read.csv2("c:/Total1.csv",sep=",") > data2 <- read.csv2("c:/GWPMax1.csv",sep=",") > M <- merge(data1, data2, by.x = "Policy.Number", by.y = "Policy.Number") > nrow(data1) [1] 20 > nrow(M) [1] 12 > No_GWPMax <- nrow(data1)-nrow(M) > (NbOfPolicyWithoutGWPMax <- nrow(data1)-nrow(M)) [1] 8 > M$GWP_Max <- as.numeric(as.character(M$GWP_Max)) > class1 <- M[(M[,25]> 0 & M[,25]<1000) ,] > NbpolicyClass1 <- nrow(class1) > c...
2011 Sep 20
2
How to transfer variable names to column names?
Hello R users, I have a set of data frames for which I am tallying row numbers, as shown below. > nrow(mC_Explant) [1] 14480 > nrow(mC_Callus) [1] 23320 > nrow(mC_RegenPlant) [1] 8108 etc. I want to create a new data frame which has the variable names as column headings, and then a single row with the nrow tallies. My first step was this: dfIntron <- c(nrow(mC_Explant), nrow(mC_Callus),...
2010 Apr 17
4
how to remove one row at a time from a matrix keeping its nrow consistent
After some headache with debugging my script, I finally isolated the problem taht I am going to illustrate in the following example. I expected matrix nrow to decrease consistently till 1. Instead, when the matrix is left with one row only, its nrow jumps to 2 because the matrix gets transposed. How come ? Thank you, Maura > B <- c(1,2) > B <- rbind(B,c(3,4)) > B <- rbind(B,c(5,6)) > B [,1] [,2] B 1 2 3 4...
2018 Apr 08
2
Doubt_merging data
...pb_SJ = total_pb join: sdmdata_SM + sdmdata_T + sdmdata_P + sdmdata_F + sdmdata_SJ =total_sdmdata code: rbind, merge? total_pb<- ?? total_sdmdata<- ?? 1 absvals_SM <- extract(grid_present_SM, absences_10000) presvals_SM <- extract(grid_present_SM, LSM) pb_SM <- c(rep(1, nrow(presvals_SM), rep(0, nrow(absvals_SM))) sdmdata_SM <- data.frame(cbind(pb_SM, rbind(presvals_SM, absvals_SM)) ###### 2 absvals_T <- extract(grid_present_T, absences_10000) presvals_T <- extract(grid_present_T, LT) pb_T <- c(rep(1, nrow(pr...
2002 Apr 09
6
matrix dimension and for loop
Dear all, My questions are that if I have > x<-rnorm(50) > dim(x)<-c(10,5) > y=1:5 > Z<-matrix(0,NROW(x),NROW(y)) > for (j in 1:NROW(y)) Z[,j]<-x[,j]*y[j] 1. Is there any other way to write this without 'for' loop? 2. and if I don't know the dimension of x, which could be only 1 column, how could I write the command without using if (NCOL(x)==1), or something like that? (in case...
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....
2017 Jul 05
4
expand gridded matrix to higher resolution
...Is there package than can do what we need already? 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...
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(doSMP) workers &...
2011 Jul 29
4
finding a faster way to run lm on rows of predictor matrix
...hat is supported with lm runs really fast ~0.5 seconds. They are pretty much performing the same number of lm fits, so I was wondering if there was a faster way, before I try to code this up in c++. thanks!! ## sample data ### regress.y = rnorm(150) predictors = matrix(rnorm(6000*150), ncol=150, nrow=6000) ## method 1 ## data.residuals = t(apply(predictors, 1, function(x)( lm(regress.y ~ -1 + as.vecto...
2009 Jan 20
1
Creating a Sparse Matrix from a Sparse Vector
...3,] . . 1 .. New Matrix:.. newExampleMatrix 3 x 4 sparse Matrix of class "dgCMatrix" [1,] . 1 . 0.5 [2,] . 1 . 0.5 [3,] . 1 . 0.5 When I try the following I get a memory allocation error due to the size of the array or vector: newExampleMatrix<-Matrix(rep(exampleMatrix[2,],times=nrow (exampleMatrix)),nrow=nrow(exampleMatrix),ncol=ncol (exampleMatrix),byrow=TRUE,sparse=TRUE) newExampleMatrix<-Matrix(exampleMatrix[2,],nrow=nrow (exampleMatrix),ncol=ncol(exampleMatrix),byrow=TRUE,sparse=TRUE) When I tried the next set, I got the error "Error in Matrix(as(rep (exampleMatr...