format a time series as dataframe with julian date

user3290596

I have a time series tt.txt of daily data from 1st May 1998 to 31 October 2012 in one column as this:

    v1
   296.172
   303.24
   303.891
   304.603
   304.207
   303.22
   303.137
   303.343
   304.203
   305.029
   305.099
   304.681
   304.32
   304.471
   305.022
   304.938
   304.298
   304.120

Each number in the text file represents the maximum temperature in kelvin for the corresponding day. I want to put the data in 3 columns as follows by adding year, jday, and the value of the data:

     year jday MAX_TEMP 
1    1959  325 11.7      
2    1959  326 15.6      
3    1959  327 14.4    
akrun

If you have a vector with dates, we can convert it to 'year' and 'jday' by

v1 <- c('May 1998 05', 'October 2012 10')
v2 <- format(as.Date(v1, '%b %Y %d'), '%Y %j')
df1 <- read.table(text=v2, header=FALSE, col.names=c('year', 'jday'))
df1
#  year jday
#1 1998  125
#2 2012  284

To convert back from '%Y %j' to 'Date' class

df1$date <- as.Date(do.call(paste, df1[1:2]), '%Y %j')

Update

We can read the dataset with read.table. Create a sequence of dates using seq if we know the start and end dates, cbind with the original dataset after changing the format of 'date' to 'year' and 'julian day'.

dat <- read.table('tt.txt', header=TRUE)
date <- seq(as.Date('1998-05-01'), as.Date('2012-10-31'), by='day')
dat2 <- cbind(read.table(text=format(date, '%Y %j'), 
              col.names=c('year', 'jday')),MAX_TEMP=dat[1])

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

What is this date and time format?

分類Dev

Parse Date and Time in specific format

分類Dev

Convert GMT date format to only time format

分類Dev

How to remove inconsistencies from dataframe (time series)

分類Dev

upsampling multiple time series in one dataframe

分類Dev

Expand time series data in pandas dataframe

分類Dev

pandas date-time format VS google sheets date format

分類Dev

How to change Date/Time format to English?

分類Dev

How to get current date time format in SQlite?

分類Dev

Karati Api - Validating date and time format

分類Dev

Inconsistent date time format for German locale

分類Dev

Convert miliseconds to date and time and format by locale

分類Dev

R : how to define date and time format

分類Dev

How to change date-time format?

分類Dev

convert text string to date/time format

分類Dev

PHP - Convert this string to another date/time format

分類Dev

Formatter in DateTimeFormatter for ISO 8601 date format of the time

分類Dev

Changing the date format of the column values in aSspark dataframe

分類Dev

How can I format date_space_hour to a time format

分類Dev

Date time conversion in Javascript from format "/Date(1535515200000)/"

分類Dev

Can NSDateFormatter format a date relative to a time other than the current time?

分類Dev

how to convert python time.time() to date format for sql insertion

分類Dev

How to format the given time string and convert to date/time object

分類Dev

How to convert to a time series and plot a dataframe with each day as a variable or column?

分類Dev

How to convert to a time series and plot a dataframe with each day as a variable or column?

分類Dev

Python pandas: insert rows for missing dates, time series in groupby dataframe

分類Dev

How to plot beautifully the segmentation of time series (pandas dataframe)

分類Dev

Finding historical seasonal average for given month in a monthly series in a dataframe time-series

分類Dev

Spring @RequestParam DateTime format as ISO 8601 Date Optional Time

Related 関連記事

  1. 1

    What is this date and time format?

  2. 2

    Parse Date and Time in specific format

  3. 3

    Convert GMT date format to only time format

  4. 4

    How to remove inconsistencies from dataframe (time series)

  5. 5

    upsampling multiple time series in one dataframe

  6. 6

    Expand time series data in pandas dataframe

  7. 7

    pandas date-time format VS google sheets date format

  8. 8

    How to change Date/Time format to English?

  9. 9

    How to get current date time format in SQlite?

  10. 10

    Karati Api - Validating date and time format

  11. 11

    Inconsistent date time format for German locale

  12. 12

    Convert miliseconds to date and time and format by locale

  13. 13

    R : how to define date and time format

  14. 14

    How to change date-time format?

  15. 15

    convert text string to date/time format

  16. 16

    PHP - Convert this string to another date/time format

  17. 17

    Formatter in DateTimeFormatter for ISO 8601 date format of the time

  18. 18

    Changing the date format of the column values in aSspark dataframe

  19. 19

    How can I format date_space_hour to a time format

  20. 20

    Date time conversion in Javascript from format "/Date(1535515200000)/"

  21. 21

    Can NSDateFormatter format a date relative to a time other than the current time?

  22. 22

    how to convert python time.time() to date format for sql insertion

  23. 23

    How to format the given time string and convert to date/time object

  24. 24

    How to convert to a time series and plot a dataframe with each day as a variable or column?

  25. 25

    How to convert to a time series and plot a dataframe with each day as a variable or column?

  26. 26

    Python pandas: insert rows for missing dates, time series in groupby dataframe

  27. 27

    How to plot beautifully the segmentation of time series (pandas dataframe)

  28. 28

    Finding historical seasonal average for given month in a monthly series in a dataframe time-series

  29. 29

    Spring @RequestParam DateTime format as ISO 8601 Date Optional Time

ホットタグ

アーカイブ