[R] converting multiple columns from POSIX* to Date
fjbuch at gmail.com
Thu Dec 11 00:47:54 CET 2008
I will try that but I am somewhat skeptical since when I go
class(date.of.birth) I get not just one word but two: "POSIXt"
"POSIXct". Will that not mess up the logical test
When I tried the following:
every item was false
GrandCentral Tel: (412) 567-7870
> Dear Farrel,
> Determine the class of each column and apply as.Date() just to those which
> class is POSIX. For more details see ?class. Here is an example assuming
> that you're data is named "mydata":
> apply(mydata, 2, function(x) ifelse( class(x)=="POSIXt" |
> class(x)=="POSIXlt" , as.Date(x) , x ) )
> On Wed, Dec 10, 2008 at 6:26 PM, Farrel Buchinsky <fjbuch at gmail.com> wrote:
>> converting a POSIX class variable to a date class is easy.
>> dates<-as.Date(x) #where X is of class POSIX
>> How does one do that to all columns in a data frame that are of POSIX
>> class and leave all the other columns (integers, factors) as is.
>> Feel free to reply with just one or two buzzwords that I could then
>> search for to find how to do it.
>> Farrel Buchinsky
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help