different formats of dates using as.POSIXct() or similar
up vote
0
down vote
favorite
I am writing a function where I plot several different data frames composed by time series.
The data frames are composed by several columns. The first one of each is always "time", and the following are the parameters.
Any data frame is different from each other
Once I imported the data set, the function create a calendar vector "Time"
Time <- as.POSIXct(TS[,1])
In a for loop, I use the function xts() to create the time series of one single parameter (one by one), using the column "time" to order the time series.
xts(TS[,i],order.by = Time)
then I plot.
As result, the script looks like this
TS <- read.table("ts.txt",header = T, dec = ".")
Time <- as.POSIXct(TS[,1])
for (i in 2:length(TS[1,])
{
p <- plot(xts(TS[,i],order.by = Time)
print(p)
}
I have problems with as.POSIXct()
when the format of my vector time in the data frames is not yyyy-mm-dd. Here few examples:
In some data frames, in "time" I have only "yyyy" in which pasting the "mm-dd" to "yyyy", would not make any sense because of the data (the columns, in this case, are the months).
In other situations, I have also negative dates because they are BC.
Are there other functions I can use to create calendar dates suitable to xts()
using a different format like mine?
Here three examples of data set I have the problem with:
#1
year <- c(seq(1900, 2000, by = 10))
Jan <- c(rnorm(length(year), mean = 1, 5))
Feb <- c(rnorm(length(year), mean = 6, 9))
TS <- as.data.frame(cbind(year,Jan,Feb))
str(TS)
#2
year <- c(seq(-500, 2000, by = 100))
Jan <- c(rnorm(length(year), mean = 1, 5))
Feb <- c(rnorm(length(year), mean = 6, 9))
TS <- as.data.frame(cbind(year,Jan,Feb))
str(TS)
#3
time <- c("-100/01/01", "-100/06/01", "0/01/01", "1400/01/01", "2000/01/01")
people <- abs(c(rnorm(length(time), mean = 6, 9)))
TS <- as.data.frame(cbind(time,people))
str(TS)
r xts
add a comment |
up vote
0
down vote
favorite
I am writing a function where I plot several different data frames composed by time series.
The data frames are composed by several columns. The first one of each is always "time", and the following are the parameters.
Any data frame is different from each other
Once I imported the data set, the function create a calendar vector "Time"
Time <- as.POSIXct(TS[,1])
In a for loop, I use the function xts() to create the time series of one single parameter (one by one), using the column "time" to order the time series.
xts(TS[,i],order.by = Time)
then I plot.
As result, the script looks like this
TS <- read.table("ts.txt",header = T, dec = ".")
Time <- as.POSIXct(TS[,1])
for (i in 2:length(TS[1,])
{
p <- plot(xts(TS[,i],order.by = Time)
print(p)
}
I have problems with as.POSIXct()
when the format of my vector time in the data frames is not yyyy-mm-dd. Here few examples:
In some data frames, in "time" I have only "yyyy" in which pasting the "mm-dd" to "yyyy", would not make any sense because of the data (the columns, in this case, are the months).
In other situations, I have also negative dates because they are BC.
Are there other functions I can use to create calendar dates suitable to xts()
using a different format like mine?
Here three examples of data set I have the problem with:
#1
year <- c(seq(1900, 2000, by = 10))
Jan <- c(rnorm(length(year), mean = 1, 5))
Feb <- c(rnorm(length(year), mean = 6, 9))
TS <- as.data.frame(cbind(year,Jan,Feb))
str(TS)
#2
year <- c(seq(-500, 2000, by = 100))
Jan <- c(rnorm(length(year), mean = 1, 5))
Feb <- c(rnorm(length(year), mean = 6, 9))
TS <- as.data.frame(cbind(year,Jan,Feb))
str(TS)
#3
time <- c("-100/01/01", "-100/06/01", "0/01/01", "1400/01/01", "2000/01/01")
people <- abs(c(rnorm(length(time), mean = 6, 9)))
TS <- as.data.frame(cbind(time,people))
str(TS)
r xts
3
"Parsing dates" is an impossibly broad issue, can you please provide some more specific example input data that you're working with
– MichaelChirico
Nov 21 at 8:38
Thanks Micheal, Here you can find a few examples as you required
– Strobila
Nov 25 at 9:02
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am writing a function where I plot several different data frames composed by time series.
The data frames are composed by several columns. The first one of each is always "time", and the following are the parameters.
Any data frame is different from each other
Once I imported the data set, the function create a calendar vector "Time"
Time <- as.POSIXct(TS[,1])
In a for loop, I use the function xts() to create the time series of one single parameter (one by one), using the column "time" to order the time series.
xts(TS[,i],order.by = Time)
then I plot.
As result, the script looks like this
TS <- read.table("ts.txt",header = T, dec = ".")
Time <- as.POSIXct(TS[,1])
for (i in 2:length(TS[1,])
{
p <- plot(xts(TS[,i],order.by = Time)
print(p)
}
I have problems with as.POSIXct()
when the format of my vector time in the data frames is not yyyy-mm-dd. Here few examples:
In some data frames, in "time" I have only "yyyy" in which pasting the "mm-dd" to "yyyy", would not make any sense because of the data (the columns, in this case, are the months).
In other situations, I have also negative dates because they are BC.
Are there other functions I can use to create calendar dates suitable to xts()
using a different format like mine?
Here three examples of data set I have the problem with:
#1
year <- c(seq(1900, 2000, by = 10))
Jan <- c(rnorm(length(year), mean = 1, 5))
Feb <- c(rnorm(length(year), mean = 6, 9))
TS <- as.data.frame(cbind(year,Jan,Feb))
str(TS)
#2
year <- c(seq(-500, 2000, by = 100))
Jan <- c(rnorm(length(year), mean = 1, 5))
Feb <- c(rnorm(length(year), mean = 6, 9))
TS <- as.data.frame(cbind(year,Jan,Feb))
str(TS)
#3
time <- c("-100/01/01", "-100/06/01", "0/01/01", "1400/01/01", "2000/01/01")
people <- abs(c(rnorm(length(time), mean = 6, 9)))
TS <- as.data.frame(cbind(time,people))
str(TS)
r xts
I am writing a function where I plot several different data frames composed by time series.
The data frames are composed by several columns. The first one of each is always "time", and the following are the parameters.
Any data frame is different from each other
Once I imported the data set, the function create a calendar vector "Time"
Time <- as.POSIXct(TS[,1])
In a for loop, I use the function xts() to create the time series of one single parameter (one by one), using the column "time" to order the time series.
xts(TS[,i],order.by = Time)
then I plot.
As result, the script looks like this
TS <- read.table("ts.txt",header = T, dec = ".")
Time <- as.POSIXct(TS[,1])
for (i in 2:length(TS[1,])
{
p <- plot(xts(TS[,i],order.by = Time)
print(p)
}
I have problems with as.POSIXct()
when the format of my vector time in the data frames is not yyyy-mm-dd. Here few examples:
In some data frames, in "time" I have only "yyyy" in which pasting the "mm-dd" to "yyyy", would not make any sense because of the data (the columns, in this case, are the months).
In other situations, I have also negative dates because they are BC.
Are there other functions I can use to create calendar dates suitable to xts()
using a different format like mine?
Here three examples of data set I have the problem with:
#1
year <- c(seq(1900, 2000, by = 10))
Jan <- c(rnorm(length(year), mean = 1, 5))
Feb <- c(rnorm(length(year), mean = 6, 9))
TS <- as.data.frame(cbind(year,Jan,Feb))
str(TS)
#2
year <- c(seq(-500, 2000, by = 100))
Jan <- c(rnorm(length(year), mean = 1, 5))
Feb <- c(rnorm(length(year), mean = 6, 9))
TS <- as.data.frame(cbind(year,Jan,Feb))
str(TS)
#3
time <- c("-100/01/01", "-100/06/01", "0/01/01", "1400/01/01", "2000/01/01")
people <- abs(c(rnorm(length(time), mean = 6, 9)))
TS <- as.data.frame(cbind(time,people))
str(TS)
r xts
r xts
edited Nov 22 at 8:48
asked Nov 21 at 8:31
Strobila
3418
3418
3
"Parsing dates" is an impossibly broad issue, can you please provide some more specific example input data that you're working with
– MichaelChirico
Nov 21 at 8:38
Thanks Micheal, Here you can find a few examples as you required
– Strobila
Nov 25 at 9:02
add a comment |
3
"Parsing dates" is an impossibly broad issue, can you please provide some more specific example input data that you're working with
– MichaelChirico
Nov 21 at 8:38
Thanks Micheal, Here you can find a few examples as you required
– Strobila
Nov 25 at 9:02
3
3
"Parsing dates" is an impossibly broad issue, can you please provide some more specific example input data that you're working with
– MichaelChirico
Nov 21 at 8:38
"Parsing dates" is an impossibly broad issue, can you please provide some more specific example input data that you're working with
– MichaelChirico
Nov 21 at 8:38
Thanks Micheal, Here you can find a few examples as you required
– Strobila
Nov 25 at 9:02
Thanks Micheal, Here you can find a few examples as you required
– Strobila
Nov 25 at 9:02
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407960%2fdifferent-formats-of-dates-using-as-posixct-or-similar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
"Parsing dates" is an impossibly broad issue, can you please provide some more specific example input data that you're working with
– MichaelChirico
Nov 21 at 8:38
Thanks Micheal, Here you can find a few examples as you required
– Strobila
Nov 25 at 9:02