reading ascii file in R - r

I am trying to read a file (ascii) in R using read.table
The file looks like the following:
DAILY MAXIMUM TEMPARATURE
YEAR DAY MT DT LAT. 66.5 67.5 68.5 69.5 70.5
1969 001 01 01 6.5 99.90 99.90 31.90 99.90 99.90
1969 001 01 01 7.5 99.90 20.90 99.90 99.90 23.90
1969 001 01 01 8.5 99.90 99.90 30.90 99.90 18.90
.....
.....
YEAR DAY MT DT LAT. 66.5 67.5 68.5 69.5 70.5
1969 001 01 02 6.5 21.90 99.90 99.90 99.90 99.90
1969 001 01 02 7.5 99.90 33.90 99.90 99.90 99.90
1969 001 01 02 8.5 99.90 99.90 15.90 99.90 99.90
.....
.....
YEAR DAY MT DT LAT. 66.5 67.5 68.5 69.5 70.5
1969 001 01 03 6.5 99.90 99.90 99.90 99.90 99.90
1969 001 01 03 7.5 99.90 99.90 99.90 99.90 99.90
1969 001 01 03 8.5 99.90 99.90 99.90 99.90 99.90
.....
.....
I read it using:
inp=read.table("MAXT1969.TXT",skip=1,header=T)
The file has been read and the contents are in the variable inp.
I have 2 questions -
I. the command to see the first 5 columns gives some extra information along with the desired output,
for example, inp[1,5] gives the following output:
> inp[1,5]
"[1] 6.5
33 Levels: 10.5 11.5 12.5 13.5 14.5 15.5 16.5 17.5 18.5 19.5 20.5 21.5 ... LAT."
I don't want the extra info but only the value. Where I am going wrong?
II. After every 32 rows, I've a header (YEAR DAY ....). How to ignore reading the header at regular intervals?

Try comment.char="Y" which will make read.table ignore all the lines starting with Y.
stringsAsFactors=FALSE will avoid converting strings to factors.
inp <- read.table("MAXT1969.TXT", skip = 1, header=FALSE, comment.char="Y", stringsAsFactors=FALSE )
#Read just first row to get header names
cols <- read.table("MAXT1969.TXT", header=FALSE, skip=1, nrows=1 )
names(inp) <- cols
inp
## YEAR DAY MT DT LAT. 66.5 67.5 68.5 69.5 70.5
## 1 1969 1 1 1 6.5 99.9 99.9 31.9 99.9 99.9
## 2 1969 1 1 1 7.5 99.9 20.9 99.9 99.9 23.9
## 3 1969 1 1 1 8.5 99.9 99.9 30.9 99.9 18.9
## 4 1969 1 1 2 6.5 21.9 99.9 99.9 99.9 99.9
## 5 1969 1 1 2 7.5 99.9 33.9 99.9 99.9 99.9
## 6 1969 1 1 2 8.5 99.9 99.9 15.9 99.9 99.9
## 7 1969 1 1 3 6.5 99.9 99.9 99.9 99.9 99.9
## 8 1969 1 1 3 7.5 99.9 99.9 99.9 99.9 99.9
## 9 1969 1 1 3 8.5 99.9 99.9 99.9 99.9 99.9
#Since the stringsAsFactor = FALSE was used numbers were read correctly.
inp[1, 5]
## [1] 6.5

Question 1: This means that you value has been read as a factor, i.e. a categorical variable. Just use as.numeric on the column to transform it from factor to numeric. Alternatively, you can use the colClasses argument to read.table to directly specify the type of the columns in the file.
Question 2: You can read the lines using readLines, find the lines that start with YEAR using grep, delete those, and read this edited output into a data.frame using read.table(textConnection(edited_data)). I would use #geektrader's solution in stead, but I just wanted to add this for completeness sake.

Another solution would be to introduce NAs and then omit them -
inp = as.data.frame(na.omit(apply(apply(inp, 2, as.character), 2, as.numeric)))

Related

How to sample data non-random

I have weather dataset my data is date-dependent
I want to predict the temperature from 07 May 2008 until 18 May 2008 (which is maybe a total of 10-15 observations) my data size is around 200
I will be using decision tree/RF and SVM & NN to make my prediction
I've never handled data like this so I'm not sure how to sample non random data
I want to sample data 80% train data and 30% test data but I want to sample the data in the original order not randomly. Is that possible ?
install.packages("rattle")
install.packages("RGtk2")
library("rattle")
seed <- 42
set.seed(seed)
fname <- system.file("csv", "weather.csv", package = "rattle")
dataset <- read.csv(fname, encoding = "UTF-8")
dataset <- dataset[1:200,]
dataset <- dataset[order(dataset$Date),]
set.seed(321)
sample_data = sample(nrow(dataset), nrow(dataset)*.8)
test<-dataset[sample_data,] # 30%
train<-dataset[-sample_data,] # 80%
output
> head(dataset)
Date Location MinTemp MaxTemp Rainfall Evaporation Sunshine WindGustDir WindGustSpeed
1 2007-11-01 Canberra 8.0 24.3 0.0 3.4 6.3 NW 30
2 2007-11-02 Canberra 14.0 26.9 3.6 4.4 9.7 ENE 39
3 2007-11-03 Canberra 13.7 23.4 3.6 5.8 3.3 NW 85
4 2007-11-04 Canberra 13.3 15.5 39.8 7.2 9.1 NW 54
5 2007-11-05 Canberra 7.6 16.1 2.8 5.6 10.6 SSE 50
6 2007-11-06 Canberra 6.2 16.9 0.0 5.8 8.2 SE 44
WindDir9am WindDir3pm WindSpeed9am WindSpeed3pm Humidity9am Humidity3pm Pressure9am
1 SW NW 6 20 68 29 1019.7
2 E W 4 17 80 36 1012.4
3 N NNE 6 6 82 69 1009.5
4 WNW W 30 24 62 56 1005.5
5 SSE ESE 20 28 68 49 1018.3
6 SE E 20 24 70 57 1023.8
Pressure3pm Cloud9am Cloud3pm Temp9am Temp3pm RainToday RISK_MM RainTomorrow
1 1015.0 7 7 14.4 23.6 No 3.6 Yes
2 1008.4 5 3 17.5 25.7 Yes 3.6 Yes
3 1007.2 8 7 15.4 20.2 Yes 39.8 Yes
4 1007.0 2 7 13.5 14.1 Yes 2.8 Yes
5 1018.5 7 7 11.1 15.4 Yes 0.0 No
6 1021.7 7 5 10.9 14.8 No 0.2 No
> head(test)
Date Location MinTemp MaxTemp Rainfall Evaporation Sunshine WindGustDir WindGustSpeed
182 2008-04-30 Canberra -1.8 14.8 0.0 1.4 7.0 N 28
77 2008-01-16 Canberra 17.9 33.2 0.0 10.4 8.4 N 59
88 2008-01-27 Canberra 13.2 31.3 0.0 6.6 11.6 WSW 46
58 2007-12-28 Canberra 15.1 28.3 14.4 8.8 13.2 NNW 28
96 2008-02-04 Canberra 18.2 22.6 1.8 8.0 0.0 ENE 33
126 2008-03-05 Canberra 12.0 27.6 0.0 6.0 11.0 E 46
WindDir9am WindDir3pm WindSpeed9am WindSpeed3pm Humidity9am Humidity3pm Pressure9am
182 E N 2 19 80 40 1024.2
77 N NNE 15 20 58 62 1008.5
88 N WNW 4 26 71 28 1013.1
58 NNW NW 6 13 73 44 1016.8
96 SSE ENE 7 13 92 76 1014.4
126 SSE WSW 7 6 69 35 1025.5
Pressure3pm Cloud9am Cloud3pm Temp9am Temp3pm RainToday RISK_MM RainTomorrow
182 1020.5 1 7 5.3 13.9 No 0.0 No
77 1006.1 6 7 24.5 23.5 No 4.8 Yes
88 1009.5 1 4 19.7 30.7 No 0.0 No
58 1013.4 1 5 18.3 27.4 Yes 0.0 No
96 1011.5 8 8 18.5 22.1 Yes 9.0 Yes
126 1022.2 1 1 15.7 26.2 No 0.0 No
> head(train)
Date Location MinTemp MaxTemp Rainfall Evaporation Sunshine WindGustDir WindGustSpeed
7 2007-11-07 Canberra 6.1 18.2 0.2 4.2 8.4 SE 43
9 2007-11-09 Canberra 8.8 19.5 0.0 4.0 4.1 S 48
11 2007-11-11 Canberra 9.1 25.2 0.0 4.2 11.9 N 30
16 2007-11-16 Canberra 12.4 32.1 0.0 8.4 11.1 E 46
22 2007-11-22 Canberra 16.4 19.4 0.4 9.2 0.0 E 26
25 2007-11-25 Canberra 15.4 28.4 0.0 4.4 8.1 ENE 33
WindDir9am WindDir3pm WindSpeed9am WindSpeed3pm Humidity9am Humidity3pm Pressure9am
7 SE ESE 19 26 63 47 1024.6
9 E ENE 19 17 70 48 1026.1
11 SE NW 6 9 74 34 1024.4
16 SE WSW 7 9 70 22 1017.9
22 ENE E 6 11 88 72 1010.7
25 SSE NE 9 15 85 31 1022.4
Pressure3pm Cloud9am Cloud3pm Temp9am Temp3pm RainToday RISK_MM RainTomorrow
7 1022.2 4 6 12.4 17.3 No 0.0 No
9 1022.7 7 7 14.1 18.9 No 16.2 Yes
11 1021.1 1 2 14.6 24.0 No 0.2 No
16 1012.8 0 3 19.1 30.7 No 0.0 No
22 1008.9 8 8 16.5 18.3 No 25.8 Yes
25 1018.6 8 2 16.8 27.3 No 0.0 No
I use mtcars as an example. An option to non-randomly split your data in train and test is to first create a sample size based on the number of rows in your data. After that you can use split to split the data exact at the 80% of your data. You using the following code:
smp_size <- floor(0.80 * nrow(mtcars))
split <- split(mtcars, rep(1:2, each = smp_size))
With the following code you can turn the split in train and test:
train <- split$`1`
test <- split$`2`
Let's check the number of rows:
> nrow(train)
[1] 25
> nrow(test)
[1] 7
Now the data is split in train and test without losing their order.

Define multiple columns when reading a txt file into R [duplicate]

This question already has answers here:
Reading text file with multiple space as delimiter in R
(3 answers)
Closed 1 year ago.
I am trying to read wave height data into R using this website
https://www.ndbc.noaa.gov/download_data.php?filename=51201h2017.txt.gz&dir=data/historical/stdmet/
my code is
buoy <- 51211
year <- 2017
one_yr <- paste0("https://www.ndbc.noaa.gov/view_text_file.php?filename=",
buoy, "h", year, ".txt.gz&dir=data/historical/stdmet/")
oneBuoy_oneYR.df <- read.csv(one_yr, fill = TRUE)
The resulting output is a data frame that has one column and 8985 observations. I have tried using sep = " " but there are some columns that are separated with two spaces instead of one. I have also tried read.delim
I'm sure there is an easy solution, I just haven't found it.
Use fread from data.table. fread will detetec the separator and colClasses automatically for you.
library(data.table)
#> Warning: package 'data.table' was built under R version 4.0.4
buoy <- 51211
year <- 2017
one_yr <- paste0("https://www.ndbc.noaa.gov/view_text_file.php?filename=",
buoy, "h", year, ".txt.gz&dir=data/historical/stdmet/")
oneBuoy_oneYR.df <- fread(one_yr, fill = TRUE)
head(oneBuoy_oneYR.df)
#> #YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP
#> 1: #yr mo dy hr mn degT m/s m/s m sec sec degT hPa degC degC degC
#> 2: 2017 06 07 14 30 999 99.0 99.0 0.58 15.38 5.66 161 9999.0 999.0 26.4 999.0
#> 3: 2017 06 07 15 00 999 99.0 99.0 0.58 15.38 5.61 156 9999.0 999.0 26.4 999.0
#> 4: 2017 06 07 15 30 999 99.0 99.0 0.55 12.50 5.37 161 9999.0 999.0 26.3 999.0
#> 5: 2017 06 07 16 30 999 99.0 99.0 0.64 12.50 4.97 158 9999.0 999.0 26.3 999.0
#> 6: 2017 06 07 17 00 999 99.0 99.0 0.64 15.38 4.95 158 9999.0 999.0 26.3 999.0
#> VIS TIDE
#> 1: mi ft
#> 2: 99.0 99.00
#> 3: 99.0 99.00
#> 4: 99.0 99.00
#> 5: 99.0 99.00
#> 6: 99.0 99.00
Created on 2021-05-31 by the reprex package (v0.3.0)

How can I get my very basic script in r to work

I am trying to write my first very basic script in r. Going through various posts and r tutorials is not taking me far. The issue am trying to resolve is as follows:
I have the following hourly data in a file:
year mo dy time ucomp vcomp temp Rhum rain
2020 07 09 00:00 -1.1 0.5 11.8 54.0 0
2020 07 09 01:00 -1.6 0.3 10.1 62.4 0
2020 07 09 02:00 -1.6 0.4 9.2 67.2 0
2020 07 09 03:00 -2.2 0.4 8.2 70.5 0
2020 07 09 04:00 -2.2 0.7 7.5 75.2 0
2020 07 09 05:00 -1.7 0.6 7.1 80.2 0
2020 07 09 06:00 -0.7 1.0 10.0 74.9 0
2020 07 09 07:00 -2.7 -1.2 15.8 61.4 0
2020 07 09 08:00 -5.4 -3.2 19.8 51.4 0
2020 07 09 09:00 -5.6 -3.7 23.3 43.4 0
2020 07 09 10:00 -5.0 -4.1 26.1 36.0 0
2020 07 09 11:00 -4.5 -4.2 28.2 28.1 0
2020 07 09 12:00 -2.9 -3.7 29.1 25.2 0
I am trying to read this data and select the line that corresponds to the hour am at, e.g. at 10h I want to copy the line
2020 07 09 10:00 -5.0 -4.1 26.1 36.0 0
Having copied the line I want to construct the wind speed and direction from the formula
windDir <- function(ucomp, vcomp) {
(180 / pi) * atan(u/v) + ifelse(v>0,180,ifelse(u>0,360,0))
}
then write wind direction and speed as E, NE, SE, ... (depending on direction) and the other values all in another file.
Below is how far I have gone in developing my script, which is very little.
setwd("/home/zmumba/04_R_Scripts")
library (lubridate)
fileName <- "myhourly.txt"
con <- file(fileName,open="r")
my2day<-sys.date()
while (length(oneLine <- readLines(con, n = 1, warn = FALSE, header="T")) > 0) {
I believe I have to put my code here, but how?
}
close(con)
Any assistance will be appreciated.
R can certainly be tricky to learn. I see a couple issues right off the bat. For example, assigning a variable within a length call is iffy. I would highly recommend going through R for Data Science by Hadley Wickham. That would be the best way to get up to speed.

Tabulize function in R

I want to extract the table of page 112 in this pdf document:
http://publications.credit-suisse.com/tasks/render/file/index.cfm?fileid=432759CA-0A73-57F6-04C67EF7EE506040
# report 2017
url_location <-"http://publications.credit-suisse.com/tasks/render/file/index.cfm?fileid=432759CA-0A73-57F6-04C67EF7EE506040"
out <- extract_tables(url_location, pages = 112)
I have tried using these tutorials (link1,link2) about 'tabulize' package but I largely failed. There are some difficult aspects which I am not very experienced how to handle in R.
Can someone suggest something and help me with that ?
Installation
devtools::install_github("ropensci/tabulizer")
# load package
library(tabulizer)
Java deps — while getting easier to deal with — aren't necessary when the tables are this clean. Just a bit of string wrangling will get you what you need:
library(pdftools)
library(stringi)
library(tidyverse)
# read it with pdftools
book <- pdf_text("global-wealth-databook.pdf")
# go to the page
lines <- stri_split_lines(book[[113]])[[1]]
# remove footer
lines <- discard(lines, stri_detect_fixed, "Credit Suisse")
# find line before start of table
start <- last(which(stri_detect_regex(lines, "^[[:space:]]+")))+1
# find line after table
end <- last(which(lines == ""))-1
# smuch into something read.[table|csv] can read
tab <- paste0(stri_replace_all_regex(lines[start:end], "[[:space:]][[:space:]]+", "\t"), collapse="\n")
#read it
read.csv(text=tab, header=FALSE, sep="\t", stringsAsFactors = FALSE)
## V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
## 1 Egypt 56,036 3,168 324 98.1 1.7 0.2 0.0 100.0 91.7
## 2 El Salvador 3,957 14,443 6,906 66.0 32.8 1.2 0.0 100.0 65.7
## 3 Equatorial Guinea 670 8,044 2,616 87.0 12.2 0.7 0.1 100.0 77.3
## 4 Eritrea 2,401 3,607 2,036 94.5 5.4 0.1 100.0 57.1 NA
## 5 Estonia 1,040 43,158 27,522 22.5 72.2 5.1 0.2 100.0 56.4
## 6 Ethiopia 49,168 153 103 100.0 0.0 100.0 43.4 NA NA
## 7 Fiji 568 6,309 3,059 85.0 14.6 0.4 0.0 100.0 68.2
## 8 Finland 4,312 159,098 57,850 30.8 33.8 33.5 1.9 100.0 76.7
## 9 France 49,239 263,399 119,720 25.3 21.4 49.3 4.0 100.0 70.2
## 10 Gabon 1,098 15,168 7,367 62.0 36.5 1.5 0.0 100.0 68.4
## 11 Gambia 904 898 347 99.2 0.7 0.0 100.0 72.4 NA
## 12 Georgia 2,950 19,430 9,874 50.7 47.6 1.6 0.1 100.0 66.8
## 13 Germany 67,244 203,946 47,091 29.5 33.7 33.9 2.9 100.0 79.1
## 14 Ghana 14,574 809 411 99.5 0.5 0.0 100.0 66.1 NA
## 15 Greece 9,020 111,684 54,665 20.7 52.9 25.4 1.0 100.0 67.7
## 16 Grenada 70 17,523 4,625 74.0 24.3 1.5 0.2 100.0 81.5
## 17 Guinea 5,896 814 374 99.4 0.6 0.0 100.0 69.7 NA
## 18 Guinea-Bissau 884 477 243 99.8 0.2 100.0 65.6 NA NA
## 19 Guyana 467 5,345 2,510 89.0 10.7 0.3 0.0 100.0 67.2
## 20 Haiti 6,172 2,879 894 96.2 3.6 0.2 0.0 100.0 76.9
## 21 Hong Kong 6,172 193,248 46,079 26.3 50.9 20.9 1.9 100.0 85.1
## 22 Hungary 7,846 39,813 30,111 11.8 83.4 4.8 0.0 100.0 45.3
## 23 Iceland 245 587,649 444,999 13.0 72.0 15.0 100.0 46.7 NA
## 24 India 834,608 5,976 1,295 92.3 7.2 0.5 0.0 100.0 83.0
## 25 Indonesia 167,559 11,001 1,914 81.9 17.0 1.1 0.1 100.0 83.7
## 26 Iran 56,306 3,831 1,856 94.1 5.7 0.2 0.0 100.0 67.3
## 27 Ireland 3,434 248,466 84,592 31.2 22.7 42.3 3.6 100.0 81.3
## 28 Israel 5,315 198,406 78,244 22.3 38.7 36.7 2.3 100.0 74.2
## 29 Italy 48,544 223,572 124,636 21.3 22.0 54.1 2.7 100.0 66.0
## 30 Jamaica 1,962 9,485 3,717 79.0 20.2 0.8 0.0 100.0 74.3
## 31 Japan 105,228 225,057 123,724 7.9 35.7 53.9 2.6 100.0 60.9
## 32 Jordan 5,212 13,099 6,014 65.7 33.1 1.2 0.0 100.0 76.1
## 33 Kazakhstan 12,011 4,441 334 97.6 2.1 0.3 0.0 100.0 92.6
## 34 Kenya 23,732 1,809 662 97.4 2.5 0.1 0.0 100.0 77.2
## 35 Korea 41,007 160,609 67,934 20.0 40.5 37.8 1.7 100.0 70.0
## 36 Kuwait 2,996 97,304 37,788 30.3 48.3 20.4 1.0 100.0 76.9
## 37 Kyrgyzstan 3,611 4,689 2,472 92.7 7.0 0.2 0.0 100.0 62.9
## 38 Laos 3,849 5,662 1,382 94.6 4.7 0.7 0.0 100.0 84.9
## 39 Latvia 1,577 27,631 17,828 29.0 68.6 2.2 0.1 100.0 53.6
## 40 Lebanon 4,085 24,161 6,452 69.0 28.5 2.3 0.2 100.0 82.0
## 41 Lesotho 1,184 3,163 945 95.9 3.8 0.3 0.0 100.0 79.8
## 42 Liberia 2,211 2,193 959 97.3 2.6 0.1 0.0 100.0 71.6
## 43 Libya 4,007 45,103 24,510 29.6 61.1 9.2 0.2 100.0 59.9
## 44 Lithuania 2,316 27,507 17,931 27.3 70.4 2.1 0.1 100.0 51.6
## 45 Luxembourg 450 313,687 167,664 17.0 20.0 58.8 4.2 100.0 68.1
## 46 Macedonia 1,607 9,044 5,698 77.0 22.5 0.5 0.0 100.0 56.4
UPDATE
This is more generic but you'll still have to do some manual cleanup. I think you would even if you used Tabula.
library(pdftools)
library(stringi)
library(tidyverse)
# read it with pdftools
book <- pdf_text("~/Downloads/global-wealth-databook.pdf")
transcribe_page <- function(book, pg) {
# go to the page
lines <- stri_split_lines(book[[pg]])[[1]]
# remove footer
lines <- discard(lines, stri_detect_fixed, "Credit Suisse")
# find line before start of table
start <- last(which(stri_detect_regex(lines, "^[[:space:]]+")))+1
# find line after table
end <- last(which(lines == ""))-1
# get the target rows
rows <- lines[start:end]
# map out where data values are
stri_replace_first_regex(rows, "([[:alpha:]]) ([[:alpha:]])", "$1_$2") %>%
stri_replace_all_regex("[^[:blank:]]", "X") %>%
map(~rle(strsplit(.x, "")[[1]])) -> pos
# compute the number of data fields
nfields <- ceiling(max(map_int(pos, ~length(.x$lengths))) / 2)
# do our best to get them into columns
data_frame(rec = rows) %>%
separate(rec, into=sprintf("X%s", 1:nfields), sep="[[:space:]]{2,}", fill="left") %>%
print(n=length(rows))
}
transcribe_page(book, 112)
transcribe_page(book, 113)
transcribe_page(book, 114)
transcribe_page(book, 115)
Take a look at the outputs for ^^. They aren't in terrible shape and some of the cleanup can be programmatic.

Loading a csv file as a ts

Below are monthly prices of a particular stock;
Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2008 46.09 50.01 48 48 50.15 43.45 41.05 41.67 36.66 25.02 22.98 22
2009 20.98 15 13.04 14.4 26.46 14.32 14.6 11.83 14 14.4 13.07 13.6
2010 15.31 15.71 18.97 15.43 13.5 13.8 14.21 12.73 12.35 13.17 14.59 15.01
2011 15.3 15.22 15.23 15 15.1 14.66 14.8 12.02 12.41 12.9 11.6 12.18
2012 12.45 13.33 12.4 14.16 13.99 13.75 14.4 15.38 16.3 18.02 17.29 19.49
2013 20.5 20.75 21.3 20.15 22.2 19.8 19.75 19.71 19.99 21.54 21.3 27.4
2014 23.3 20.5 20 22.7 25.4 25.05 25.08 24.6 24.5 21.2 20.52 18.41
2015 16.01 17.6 20.98 21.15 21.44 0 0 0 0 0 0 0
I want to decompose the data into seasonal and trend data but I am not getting a result.
How can I load the data as a "ts" class data so I can decompose it?
Here is a solution using tidyr, which is fairly accessible.
library(dplyr); library(tidyr)
data %>% gather(month, price, -Year) %>% # 1 row per year-month pair, name the value "price"
mutate(synth_date_txt= paste(month,"1,",Year), # combine month and year into a date string
date=as.Date(synth_date_txt,format="%b %d, %Y")) %>% # convert date string to date
select(date, price) # keep just the date and price
# date price
# 1 2008-01-01 46.09
# 2 2009-01-01 20.98
# 3 2010-01-01 15.31
# 4 2011-01-01 15.30
# 5 2012-01-01 12.45
This gives you an answer with date format (even though you didn't specify a date, just a month and year). It should work for your time series analysis, but if you really need a timestamp you can just use as.POSIXct(date)
Mike,
The program is R and below is the code I have tried.
sev=read.csv("X7UPM.csv")
se=ts(sev,start=c(2008, 1), end=c(2015,1), frequency=12)
se
se=se[,1]
S=decompose(se)
plot(se,col=c("blue"))
plot(decompose(se))
S.decom=decompose(se,type="mult")
plot(S.decom)
trend=S.decom$trend
trend
seasonal=S.decom$seasonal
seasonal
ts.plot(cbind(trend,trend*seasonal),lty=1:2)
plot(stl(se,"periodic"))

Resources