[R] combining rows
David Winsemius
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
> being
> suggesting to do more advanced data analysis, but it sounds like for
> your
> 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="-"),
origin="1970-01-01")
)
with(dayRainSummary, plot(date, dailySums) )
save(dayRainSummary, file="daySummary.rda")
>
> Hope this helps,
>
> Michael Weylandt
>
> On Sun, Sep 4, 2011 at 7:16 PM, Kang Tu <kang.tu.rfan at gmail.com>
> wrote:
>
>> 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
>>> which
>> are
>>> Year,month, day, and record in hours.
>>>
>>> I am trying to combine the 4th column to the 27th to get daily
>>> rain fall
>>> data.
>>> rowSums() works in the case of merging all rows but in my case, I
>>> need to
>> be
>>> selective. How should I start?
>>>
>>>
>>> --
>>> View this message in context:
>> http://r.789695.n4.nabble.com/combining-rows-tp3790068p3790068.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.
>>
>> ______________________________________________
>> 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.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list