similar to: Column sums from a data frame (without the column headers)

Displaying 20 results from an estimated 20000 matches similar to: "Column sums from a data frame (without the column headers)"

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!
2007 Feb 08
5
remove component from list or data frame
Sorry to ask such a simple question, but I can't find the answer after extensive searching the docs and the web. How do you remove a component from a list? For example say you have: lst<-c(5,6,7,8,9) How do you remove, for example, the third component in the list? lst[[3]]]<-NULL generates an error: "Error: more elements supplied than there are to replace" Also,
2006 Mar 07
4
POSIX time zone codes
The manual entry for as.POSIX says this about time zone codes... Usage as.POSIXct(x, tz = "") tz A timezone specification to be used for the conversion... but it fails to mention what these "specifications" are. So far, I have tried... as.POSIX(x, tz="UTC") ... works, gives UTC times as.POSIX(x, tz="UTC") ... works, gives EST times as.POSIX(x,
2007 Feb 09
2
Replace individual values in a data frame with NA
I'd like to replace a value in a data frame with an NA, but can't figure out how. For example, say you have a<-c(1,2,3,4) b<-c(5,6,7,8) data<-data.frame(a,b) Now, how would you set the third row of the second column ( data [[3,2]] ) to NA? I have tried all types of permutations with is.na, including is.na<- data[[3,2]], which does not work. Thanks
2005 Oct 11
2
non-zero sequence of numbers
Can anyone think of a way to create a pretty() sequence that excludes zero? Or a way to remove the zero from a sequence after using pretty()? Thanks, - Jason Jason Horn Boston University Department of Biology 5 Cumington Street Boston, MA 02215 jhorn@bu.edu office: 617 353 6987 cell: 401 588 2766 [[alternative HTML version deleted]]
2005 Oct 10
2
R.app window size
Hi all, This is a question for any of you who use R.app (OS X). Is there any way to resize the quartz plot window from within R? I know that you can resize the window by dragging the corner of the window, and fro the preferences panel. But is there a way to specify the window size from the console? I want to specify the size of the plot window from inside an R function. Also a
2005 Oct 06
1
circular statistics plotting
Hi all, I'm new to the list here, and I have what I think is a simple question. Using the "circular" package, is there a way to plot the mean and variance on top of a rose diagram or other plot of the data? Thanks in advance... - Jason Jason Horn Boston University Department of Biology 5 Cumington Street Boston, MA 02215 jhorn@bu.edu office: 617 353 6987 cell: 401 588
2006 Oct 18
1
Select one row of a data frame
Can anyone tell me how to select just one row of a data frame? Say I want just the third row, what would be the syntax? Every notation I try just gives me columns. Thanks - Jason
2006 Feb 20
1
RMySQL Error Messages, crashing R
I am having trouble getting RMySQL working with R. It did at one point, work with an older 1.x version of R, but now with R2.2.1, I am getting the following messages on my OS X 10.4.5 system: RS-DBI driver warning: (MySQL mismatch between compiled version 4.0.24 and runtime version 4.1.14) if I then try to run any further db commands such as dbConnect, R crashes with a bus error. When
2005 Aug 05
6
Computing sums of the columns of an array
Hi, I have a 5x731 array A, and I want to compute the sums of the columns. Currently I do: apply(A, 2, sum) But it turns out, this is slow: 70% of my CPU time is spent here, even though there are many complicated steps in my computation. Is there a faster way? Thanks, Martin
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
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 11
1
Please use colMeans()! was: Re: Calculate Mean of Column Vectors?
There are indeed speed advantages in using colSums etc. However the disadvantage is that the newbie doesn't always find the power inherent in the apply, sapply, tapply and mapply. For many things that I do, the speed is the least of my worries; although I take the point that using apply for means or sums in packages that are distibuted to others is not the way to go. As many of us have found
2006 Mar 06
1
Length of a vector of POSIX objects reported incorrectly?
I have a vector of POSIX times/dates (called "times") that I want to plot. But I'm having trouble because R reports the length of the vector incorrectly. Can someone help me figure out what's going on here? This code.... print(times) print(class(times)) print(length(times)) Produces this... . . . [355] "2006-03-06 18:34:00" "2006-03-06 18:32:00"
2006 Mar 07
1
How to change time zones?
Say you have a POSIX object that is in UTC. How do you change the values to another timezone? If I do this: times <- strptime(times, "%H:%M:%S") times1 <- as.POSIXct(times, tz="UTC") times2 <- as.POSIXct(times, tz="CDT6CST") times1 id UTC, but times2 is still UTC, not CTD. Why? Is the only was to change time zones to add seconds to POSIX objects?
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
2010 Nov 28
4
how to divide each column in a matrix by its colSums?
Hi, I have a matrix, say m=matrix(c( 983,679,134, 383,416,84, 2892,2625,570 ),nrow=3 ) i can find its row/col sum by rowSums(m) colSums(m) How do I divide each row/column by its rowSum/colSums and still return in the matrix form? (i.e. the new rowSums/colSums =1) Thanks. Casper -- View this message in context:
2011 Aug 14
3
Not sure how to use aggregate, colSums, by
I have a data frame called test shown below that i would like to summarize in a particular way : I want to show the column sums (columns y ,f) grouped by country (column e1). However, I'm looking for the data to be split according to column e2. In other words, two tables of sum by country. One table for "con" and one table for "std" shown in column e2. Finally at the
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
2010 Sep 27
1
stacked area chart
Dear R-ers! Asking for your help with building the stacked area chart for the following simple data (several variables - with date on the X axis): ### Creating a data set my.data<-data.frame(date=c(20080301,20080402,20080503,20090301,20090402,20090503,20100301,20100402,20100503), x=c(1.1,1.0,1.6,1,2,1.5,2.1,1.3,1.9),y=c(-4,-3,-6,-5,-7,-5.2,-6,-4,-4.9),