similar to: Computing sums of the columns of an array

Displaying 20 results from an estimated 20000 matches similar to: "Computing sums of the columns of an array"

2008 Jun 28
2
Parallel R
Hello, The problem I'm working now requires to operate on big matrices. I've noticed that there are some packages that allows to run some commands in parallel. I've tried snow and NetWorkSpaces, without much success (they are far more slower that the normal functions) My problem is very simple, it doesn't require any communication between parallel tasks; only that it divides
2008 Feb 29
4
Column sums from a data frame (without the headers)
Does anyone know how to get a vector of column sum from a data frame? You can use colSums(), but this gives you a object of type "numeric" with the column labels in the first row, and the sums in the second row. I just want a vector of the sums, and I can't figure out a way to index the "numeric" object. Thanks!
2008 Oct 14
4
request: How to ignore columns having zero sums
Dear friends I have an array consist of r-rows and c-columns e.g. x=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0); x1=array(x, dim=c(4,6)) output is > x1 [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 2 3 4 0 0 [2,] 1 2 3 4 0 0 [3,] 1 2 3 4 0 0 [4,] 1 2 3 4 0 0 How can i ignore columns having zero sums? Help in this regard
2008 Feb 29
1
Column sums from a data frame (without the column headers)
Does anyone know how to get a vector of column sum from a data frame? You can use colSums(), but this gives you a object of type "numeric" with the column labels in the first row, and the sums in the second row. I just want a vector of the sums, and I can't figure out a way to index the "numeric" object. Thanks!
2005 Apr 15
5
Pearson corelation and p-value for matrix
Hi, I was trying to evaluate the pearson correlation and the p-values for an nxm matrix, where each row represents a vector. One way to do it would be to iterate through each row, and find its correlation value( and the p-value) with respect to the other rows. Is there some function by which I can use the matrix as input? Ideally, the output would be an nxn matrix, containing the p-values
2005 Jan 14
3
summing subsets of rows matrices
I have a large data matrix (4460X3500) and I want to sum row subsets in groups of 10 (bin). Is there an efficient way to do this in R without using loops. Looping takes forever to perform this task! For example suppose we have the matrix > matrix(1:12,6,2) [,1] [,2] [1,] 1 7 [2,] 2 8 [3,] 3 9 [4,] 4 10 [5,] 5 11 [6,] 6 12 my problem is to sdum for
2004 Dec 06
6
how to get how many lines there are in a file.
hi all If I wanna get the total number of lines in a big file without reading the file's content into R as matrix or data frame, any methods or functions? thanks in advance. Regards
2008 Aug 24
2
Eliminating columns that sum to zero
Hi all, I am trying to look for a way to eliminate columns that sum to zero. Any help would be appreciated. Wade [[alternative HTML version deleted]]
2005 Jan 24
1
Weighted.mean(x,wt) vs. t(x) %*% wt
What is the difference between the above two operations ? [[alternative HTML version deleted]]
2006 Jun 21
3
sort matrix by sum of columns
Hi all, I would like to know how can I sort the cols of a matrix by the sum of their elements. a <- matrix(as.integer(rnorm(25,4,2)),10,5) colnames(a) = c("alfa","bravo","charlie","delta","echo") I guess I should use colSums, and then rearrange the matrix somehow according to the result. My idea is to display a "sorted" barplot:
2005 Feb 25
3
Loops and dataframes
Hi, I am experiencing a long delay when using dataframes inside loops and was wordering if this is a bug or not. Example code: > st <- rep(1,100000) > ed <- rep(2,100000) > for(i in 1:length(st)) st[i] <- ed[i] # works fine > df <- data.frame(start=st,end=ed) > for(i in 1:dim(df)[1]) df[i,1] <- df[i,2] #takes for ever R: R 2.0.0 (2004-10-04) OS: Linux, Fedora Core 2
2009 Jan 20
2
Summing Select Columns of a Data Frame?
Hi, I would like to operate on certain columns in a dataframe, but not others. My data looks like this: x1 x2 x3 1 2 3 4 5 6 7 8 9 I want to create a new column named x4 that is the sum of x1 and x2, but NOT x3. I looked at colSums and apply, but those functions seem to use all the columns in a dataframe. How do I only use select columns? If it helps, in Stata this would be gen x4
2005 Jan 27
3
the incredible lightness of crossprod
The following is at least as much out of intellectual curiosity as for practical reasons. On reviewing some code written by novices to R, I came across: crossprod(x, y)[1,1] I thought, "That isn't a very S way of saying that, I wonder what the penalty is for using 'crossprod'." To my surprise the penalty was substantially negative. Handily the client had S-PLUS as
2006 Jun 12
3
NA values
Dear all R users, I am wondering whether there is any way to replace all "NA" values in a data frame by some numerical value, suppose 1000? Thanks and Regards [[alternative HTML version deleted]]
2007 Apr 25
1
Sum of specific column
I have a data set that I have imported (not sure if that makes a difference) and I would like to calculate the sum of only specific columns. I have tried >colSums(dataset, by=list(dataset$col5), dims=1) and I get an error of unused arguments I have also tried >aggregate(dataset, by=list(dataset$col5), sum) and I get the error that sum is not meaningful for factors. I want to only calculate
2004 Nov 23
2
sorting without order
Hello, In order to increase the performance of a script I'd like to sort very large vectors containing repeated integer values. I'm not interesting in having the values sorted, but only grouped. I also need the equivalent of index.return from the standard "sort" function: f(c(10,1,10,100,1,10)) => grouped: c(10,10,10,1,1,100) ix: c(1,3,6,2,5,4) is there a way
2005 May 08
3
Light-weight data.frame class: was: how to add method to .Primitive function
Hi, Encouraged by a tip from Simon Urbanek I tried to use the S3 machinery to write a faster version of the data.frame class. This quickly hits a snag: the "[.default"(x, i) for some reason cares about the dimensionality of x. In the end there is a full transcript of my R session. It includes the motivation for writing the class and the problems I have encountered. As a result I see
2005 May 04
1
Cost of method dispatching: was: when can we expect Prof Tierney's compiled R?
> -----Original Message----- > From: Prof Brian Ripley [mailto:ripley@stats.ox.ac.uk] > Sent: Wednesday, April 27, 2005 1:13 AM > To: Vadim Ogranovich > Cc: Luke Tierney; r-devel@stat.math.ethz.ch > Subject: Re: [Rd] RE: [R] when can we expect Prof Tierney's > compiled R? > > On Tue, 26 Apr 2005, Vadim Ogranovich wrote: > ... > > The arithmetic shows
2005 Nov 22
4
the matrix of rows with specific row sums
I am just starting with R and have the following problem: given a matrix of ones and zeroes, say mdim=4 m<-matrix(round(runif(mdim^mdim)),mdim,mdim) how to construct the matrix of those rows of m, whose elements sum to 2. Contrary to the random matrix above, the actual matrix always has at least one such row. Serguei Kaniovski
2009 Dec 24
3
Newbie: colSums() compared with Matlab's sum()
Hi all, I'm trying to learn R after years of Matlab's experience. Here is an issue I couldn't solve today. Consider the following piece of code (written by memory): for(i in 1:n){ submat <- data[1:i,] C <- colSums(submat) } The problem is that at the first iteration, data[1:1,] reduces to a vector and colSums returns an error. This sounds really strange to me