s-news
[Top] [All Lists]

Re: Inserting rows for OBS and NOOBS days

To: s-news@lists.biostat.wustl.edu
Subject: Re: Inserting rows for OBS and NOOBS days
From: Sarah Henderson <sarah.henderson@ubc.ca>
Date: Tue, 25 Apr 2006 09:33:34 -0700
In-reply-to: <OF864AC448.EBE0AF20-ON8625715A.0070B878-8625715A.0070EB78@usgs.gov>
References: <7.0.1.0.0.20060423171542.01b30fc0@ubc.ca> <OF864AC448.EBE0AF20-ON8625715A.0070B878-8625715A.0070EB78@usgs.gov>


Sarah,
It is very difficult to suggest an approach because you have not said what the structure of your data is. It would also help to know what version of S+ you are using. Please repost giving that info.
Dave

Thanks to David for seeking clarification, and to Clint Bowman for suggesting a solution in perl. Apologies for my naivety, but I'm not sure what David means by the "structure" of my data beyond it being a data frame object in S-PLUS. I should clarify that there is no date field, per se -- there are separate fields for day, month, study day (1 through 92) and Julian day. I am using the student version of S+ 7.0.

After posting to the list I came up with this brute-force solution, but I'm still open to suggestions for another approach:

daily.mean <- master[master$Julian.day==1,]
daily.mean <- assign.rows(daily.mean, count.rows(daily.mean)+1, value=apply(daily.mean, 2, mean))

for (i in 2:92){
        day <- master[master$Julian.day==i,]
        day <- assign.rows(day, count.rows(day)+1, value=apply(day, 2, mean))
        daily.mean <- rbind.data.frame(daily.mean, day)
}

Then I went on to write functions that estimate mean values for the days with no observations. It works, which is all that really matters, but I suspect that there must be an easier way.

Thanks to all,

Sarah







Sarah Henderson <sarah.henderson@ubc.ca>
Sent by: s-news-owner@lists.biostat.wustl.edu

04/23/2006 07:30 PM
To
s-news@lists.biostat.wustl.edu
cc
Subject
[S] Inserting rows for OBS and NOOBS days





Hello all --

I have data spanning a 92-day period.  The number of observations per
day ranges from 0 to 1000+.  I need to insert a blank row for each
day after the day's last observation.  If there are not observations,
I still need to insert a row for that day.  Is there an elegant way
to do this?

Many thanks,

Sarah

--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news


<Prev in Thread] Current Thread [Next in Thread>