Hello, I have the following data frame (DF): V5 V5.1 V5.2 V5.3 V5.4 V5.5 2 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 3 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 4 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 5 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 6 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 7 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 8 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 9 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 10 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 11 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 I would like to sum each row and output the results to another dataframe (Results). The resluts would be Results[1] <- sum(DF[1]) When I try this i get: Error in FUN(X[[1L]], ...) : only defined on a data frame with all numeric variables I have also tried apply(AFDDsec,1,sum) Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument What am I doing wrong? Eventually I would like to do this with a dataframe that has 44 columns and 5329 rows. Cheers, R -- View this message in context: http://www.nabble.com/sum-each-row-and-output-results-tp18616486p18616486.html Sent from the R help mailing list archive at Nabble.com.
Like This? my.df<-read.table(stdin(), head=T, sep=" ") V5 V5.1 V5.2 V5.3 V5.4 V5.5 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 my.df$rowSum<-rowSums(my.df) my.df or my.df.rsum<-data.frame(cbind(rsum=rowSums(my.df))) my.df.rsum Miltinho Astronauta Brazil On 7/23/08, Rheannon <rbrooks@uvic.ca> wrote:> > > Hello, > > I have the following data frame (DF): > > V5 V5.1 V5.2 V5.3 V5.4 V5.5 > 2 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 3 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 4 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 5 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 6 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 7 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 8 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 9 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 10 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 11 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > > I would like to sum each row and output the results to another dataframe > (Results). > The resluts would be > Results[1] <- sum(DF[1]) > > When I try this i get: > Error in FUN(X[[1L]], ...) : > only defined on a data frame with all numeric variables > > I have also tried > apply(AFDDsec,1,sum) > Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument > > What am I doing wrong? > Eventually I would like to do this with a dataframe that has 44 columns and > 5329 rows. > > Cheers, > R > -- > View this message in context: > http://www.nabble.com/sum-each-row-and-output-results-tp18616486p18616486.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Try this: addmargins(as.matrix(my.df), 2) On Wed, Jul 23, 2008 at 2:43 PM, Rheannon <rbrooks at uvic.ca> wrote:> > Hello, > > I have the following data frame (DF): > > V5 V5.1 V5.2 V5.3 V5.4 V5.5 > 2 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 3 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 4 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 5 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 6 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 7 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 8 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 9 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 10 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 11 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > > I would like to sum each row and output the results to another dataframe > (Results). > The resluts would be > Results[1] <- sum(DF[1]) > > When I try this i get: > Error in FUN(X[[1L]], ...) : > only defined on a data frame with all numeric variables > > I have also tried > apply(AFDDsec,1,sum) > Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument > > What am I doing wrong? > Eventually I would like to do this with a dataframe that has 44 columns and > 5329 rows. > > Cheers, > R > -- > View this message in context: http://www.nabble.com/sum-each-row-and-output-results-tp18616486p18616486.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Hi r-help-bounces at r-project.org napsal dne 23.07.2008 19:43:33:> > Hello, > > I have the following data frame (DF): > > V5 V5.1 V5.2 V5.3 V5.4 V5.5 > 2 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 3 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 4 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 5 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 6 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 7 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 8 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 9 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 10 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > 11 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 > > I would like to sum each row and output the results to another dataframe > (Results). > The resluts would be > Results[1] <- sum(DF[1]) > > When I try this i get: > Error in FUN(X[[1L]], ...) : > only defined on a data frame with all numeric variablesDoes str(AFDDsec) show that all columns are numeric? Isn't there a factoror character column? Regards Petr> > I have also tried > apply(AFDDsec,1,sum) > Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument > > What am I doing wrong? > Eventually I would like to do this with a dataframe that has 44 columnsand> 5329 rows. > > Cheers, > R > -- > View this message in context:http://www.nabble.com/sum-each-row-and-output-> results-tp18616486p18616486.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.