[R] tapply output as a dataframe

Gabor Grothendieck ggrothendieck at gmail.com
Thu Feb 3 19:18:43 CET 2011


On Thu, Feb 3, 2011 at 1:11 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On Feb 3, 2011, at 1:05 PM, Graves, Gregory wrote:
>
>> Yes, as far as I can tell, "sampling.date" is a character vector of the
>> format "1/15/2008".  It resides in the leftmost column of the tapply output.
>>
>> "station.code" are the A, B, C column headers which refer actual water
>> quality station locations, and the values below those headers correspond to
>> the "sampling.date" when samples were taken.  Actually what I have done is
>> to take the mid-point of each month and calculated its mean to deal with
>> multiple samples taken in one month, and to generate NAs where no sample was
>> taken by purposefully not adding the na.rm=T to the tapply command.
>>
>> Normally I would do this:
>>>
>>> rdate<-as.POSIXct(strptime(date,format="%m/%d/%Y")) #convert
>>> sampling.date to date R can handle
>>> plot(A~rdate)
>>
>> If I just submit station.code like
>>>
>>> A
>>
>> I get all the values for "Station A".
>>
>> It is in converting the sampling.date to an "rdate" that has me stumped.
>>  One reason being that in the tapply output the character vector
>> representing date has no column name.  I can't access that column.
>
> It looks like a zoo object. "zoo" objects hold their time values in the
> rownames attribute. But since its not really ordered properly, it may just
> be a table with rownames. The str() function applied to the object from
> tapply would tell you the answer.
>

Internally zoo objects hold their time index in the "index" attribute.

> library(zoo)
> dput(zoo(4:5))
structure(4:5, index = 1:2, class = "zoo")

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list