[R] importing timestamp data into R
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Jan 4 23:19:37 CET 2007
Try this:
Lines <- "DT_1,DT_2
[2006/08/10 21:12:14 ],[2006/08/10 21:54:00 ]
[2006/08/10 20:42:00 ],[2006/08/10 22:48:00 ]
[2006/08/10 20:58:00 ],[2006/08/10 21:39:00 ]
[2006/08/04 12:15:24 ],[2006/08/04 12:20:00 ]
[2006/08/04 12:02:00 ],[2006/08/04 14:20:00 ]
"
Lines2 <- gsub("\\[|\\]", "", readLines(textConnection(Lines)))
# using chron
library(chron)
DT <- read.csv(textConnection(Lines2))
DT[] <- lapply(DT, function(x)
chron(substring(x, 1, 10), substring(x, 12), format = c("Y/M/D", "h:m:s")))
DT
# using POSIXct
DT <- read.csv(textConnection(Lines2))
DT[] <- lapply(DT, as.POSIXct)
DT
On 1/4/07, sj <ssj1364 at gmail.com> wrote:
> I have a set of timestamp data that I have in a text file that I would like
> to import into R for analysis.
> The timestamps are formated as follows:
>
> DT_1,DT_2
> [2006/08/10 21:12:14 ],[2006/08/10 21:54:00 ]
> [2006/08/10 20:42:00 ],[2006/08/10 22:48:00 ]
> [2006/08/10 20:58:00 ],[2006/08/10 21:39:00 ]
> [2006/08/04 12:15:24 ],[2006/08/04 12:20:00 ]
> [2006/08/04 12:02:00 ],[2006/08/04 14:20:00 ]
>
> I can get them into R but I cannot figure out how to convert them into
> something R will recognize as a date/time. I have tried using "as.Date",
> strptime, and chron. Any help would be appreciated?
>
> best,
>
> Spencer
>
>
>
> On 1/4/07, Darin A. England <england at cs.umn.edu> wrote:
> >
> >
> > Does anyone know a reason why, in principle, a call to randomForest
> > cannot accept a data frame with missing predictor values? If each
> > individual tree is built using CART, then it seems like this
> > should be possible. (I understand that one may impute missing values
> > using rfImpute or some other method, but I would like to avoid doing
> > that.)
> >
> > If this functionality were available, then when the trees are being
> > constructed and when subsequent data are put through the forest, one
> > would also specify an argument for the use of surrogate rules, just
> > like in rpart.
> >
> > I realize this question is very specific to randomForest, as opposed
> > to R in general, but any comments are appreciated. I suppose I am
> > looking for someone to say "It's not appropriate, and here's why
> > ..." or "Good idea. Please implement and post your code."
> >
> > Thanks,
> >
> > Darin England, Senior Scientist
> > Ingenix
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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 stat.math.ethz.ch 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.
>
More information about the R-help
mailing list