[R] combining rows
dwinsemius at comcast.net
Mon Sep 5 04:13:46 CEST 2011
On Sep 4, 2011, at 8:35 PM, R. Michael Weylandt wrote:
> Kang Tu is right and you will certainly need to learn the techniques
> suggesting to do more advanced data analysis, but it sounds like for
> immediate problem the following might work:
> # Suppose df is your data frame
> This takes a sub-data-frame consisting only of columns 4 through 27
> and does
> rowSums on them.
And to take this a bit further you could record those results in the
same dataframe with:
df$dailySums <- rowSums(df[,4:27])
And print them out with:
df[ , c("Year", "Month", "day", dailySums") ]
Or assign them to a daySummary
dayRainSummary <- df[ , c("Year", "Month", "day", dailySims") ]
dayRainSummary$date <- with(dayRainSummary, as.POSIXct(paste(Year,
Month, day, sep="-"),
with(dayRainSummary, plot(date, dailySums) )
> Hope this helps,
> Michael Weylandt
> On Sun, Sep 4, 2011 at 7:16 PM, Kang Tu <kang.tu.rfan at gmail.com>
>> Would you mind show us a simple example of your data? It is hard to
>> understand your request directly from your text.
>> If you just want to combine the data, you can try cbind() function
>> directly, or you can use subset() function to get a subset of your
>> data.frame. If you want to selectively aggregate some statistics
>> you can
>> try aggregate() function. If you want a more complex aggregation, you
>> may want to try ddply() in 'plyr' package.
>> On Sun, 2011-09-04 at 15:25 -0700, joonsum wrote:
>>> First time using R and have so many basic questions.
>>> The problem that I have confronted is combining rows. I have a
>>> data frame
>>> that contains daily rain falls from 60 to 80. There are 27 columns
>>> Year,month, day, and record in hours.
>>> I am trying to combine the 4th column to the 27th to get daily
>>> rain fall
>>> rowSums() works in the case of merging all rows but in my case, I
>>> need to
>>> selective. How should I start?
>>> View this message in context:
>>> Sent from the R help mailing list archive at Nabble.com.
>>> R-help at r-project.org mailing list
>>> PLEASE do read the posting guide
>>> and provide commented, minimal, self-contained, reproducible code.
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help