Better way to optimize my code for getting NOAA climate data - r

So I've been working on grabbing climate data (specifically temperature, precip) from NOAA's network of GHCN weather stations. I've managed to get a list of the stations pertinent to my area (~200) and have built a loop to essentially get a certain a climate variable for every station on that list for every day of between a specified min and max date. Ultimately I need ~10 years worth of data. However my simple loop is taking forever to get this data and I was wondering if there's a better way to optimize it? Also I really want to access monthly data rather than daily but rnoaa doesn't seem to have an option for GHCN monthly data as the only available function is ghcnd_search(). If anyone also knows about how to mine monthly rather than daily data that would be appreciated
Station list:
df<-c("US1FLAL0048", "US1FLBK0003", "US1FLBV0002", "US1FLBV0006",
"US1FLBV0023", "US1FLBV0040", "US1FLBW0099", "US1FLCT0012", "US1FLDV0051",
"US1FLFR0006", "US1FLHL0003", "US1FLHN0009", "US1FLLB0001", "US1FLLE0005",
"US1FLLK0012", "US1FLLN0004", "US1FLLN0018", "US1FLMN0013", "US1FLMR0012",
"US1FLMR0033", "US1FLOK0017", "US1FLOR0028", "US1FLPS0002", "US1FLPS0018",
"US1FLPT0007", "US1FLSJ0012", "US1FLSM0008", "US1FLSS0044", "US1FLST0014",
"US1FLSW0008", "US1FLVL0035", "US1FLWK0001", "USC00080228", "USC00080236",
"USC00080369", "USC00080414", "USC00080478", "USC00080598", "USC00080737",
"USC00080945", "USC00080992", "USC00081163", "USC00081276", "USC00081306",
"USC00081544", "USC00081641", "USC00081651", "USC00081978", "USC00082008",
"USC00082046", "USC00082150", "USC00082229", "USC00082288", "USC00082298",
"USC00082391", "USC00082418", "USC00082441", "USC00082850", "USC00082915",
"USC00082944", "USC00083020", "USC00083153", "USC00083163", "USC00083168",
"USC00083207", "USC00083209", "USC00083470", "USC00083874", "USC00083909",
"USC00083956", "USC00083986", "USC00084050", "USC00084095", "USC00084210",
"USC00084289", "USC00084320", "USC00084366", "USC00084394", "USC00084412",
"USC00084461", "USC00084625", "USC00084662", "USC00084731", "USC00084802",
"USC00085076", "USC00085099", "USC00085184", "USC00085275", "USC00085359",
"USC00085377", "USC00085539", "USC00085612", "USC00085667", "USC00085879",
"USC00085895", "USC00085973", "USC00086065", "USC00086078", "USC00086129",
"USC00086240", "USC00086315", "USC00086406", "USC00086414", "USC00086618",
"USC00086657", "USC00086764", "USC00086767", "USC00086828", "USC00086842",
"USC00086999", "USC00087020", "USC00087025", "USC00087205", "USC00087228",
"USC00087261", "USC00087304", "USC00087397", "USC00087429", "USC00087760",
"USC00087826", "USC00087851", "USC00087869", "USC00087886", "USC00087982",
"USC00088368", "USC00088529", "USC00088620", "USC00088756", "USC00088782",
"USC00088824", "USC00088942", "USC00089120", "USC00089176", "USC00089219",
"USC00089401", "USC00089430", "USC00089566", "USC00089640", "USC00089795",
"USR0000FBLO", "USR0000FCAC", "USR0000FCEN", "USR0000FCHE", "USR0000FLSU",
"USR0000FMER", "USR0000FMIL", "USR0000FNAV", "USR0000FOAS", "USR0000FOCH",
"USR0000FOLU", "USR0000FRAC", "USR0000FSAN", "USR0000FSTM", "USR0000FSUM",
"USR0000FWIL", "USW00003818", "USW00003853", "USW00012812", "USW00012815",
"USW00012816", "USW00012818", "USW00012819", "USW00012832", "USW00012833",
"USW00012834", "USW00012835", "USW00012836", "USW00012838", "USW00012839",
"USW00012841", "USW00012842", "USW00012843", "USW00012844", "USW00012849",
"USW00012850", "USW00012854", "USW00012871", "USW00012873", "USW00012876",
"USW00012882", "USW00012885", "USW00012888", "USW00012894", "USW00012895",
"USW00012896", "USW00012897", "USW00013884", "USW00013889", "USW00013899",
"USW00053847", "USW00053853", "USW00053860", "USW00092805", "USW00092806",
"USW00092809", "USW00092811", "USW00092821", "USW00093805", "USW00093837",
"USW00093841")
Code:
library(rnoaa)
options(noaakey = "your api key")
data<-matrix(, nrow=0, ncol=0) #create empty matrix
for (i in 1:length(df)){
a<-ghcnd_search(stationid=df[1],var='TMAX',date_min='2010-1-30',date_max='2015-12-31')
data=rbind(data,a$tmax)
}

Assuming the station ID is stored in a vector called dat, we can use the functions from the purrr package to download the data and create a data frame.
# Load packages
library(rnoaa)
library(purrr)
# Download the data and create a data frame.
dat_df <- map(dat, ghcnd_search,
var='TMAX', date_min = '2010-1-30', date_max = '2015-12-31') %>%
map_dfr("tmax")
DATA
dat<-c("US1FLAL0048", "US1FLBK0003", "US1FLBV0002", "US1FLBV0006",
"US1FLBV0023", "US1FLBV0040", "US1FLBW0099", "US1FLCT0012", "US1FLDV0051",
"US1FLFR0006", "US1FLHL0003", "US1FLHN0009", "US1FLLB0001", "US1FLLE0005",
"US1FLLK0012", "US1FLLN0004", "US1FLLN0018", "US1FLMN0013", "US1FLMR0012",
"US1FLMR0033", "US1FLOK0017", "US1FLOR0028", "US1FLPS0002", "US1FLPS0018",
"US1FLPT0007", "US1FLSJ0012", "US1FLSM0008", "US1FLSS0044", "US1FLST0014",
"US1FLSW0008", "US1FLVL0035", "US1FLWK0001", "USC00080228", "USC00080236",
"USC00080369", "USC00080414", "USC00080478", "USC00080598", "USC00080737",
"USC00080945", "USC00080992", "USC00081163", "USC00081276", "USC00081306",
"USC00081544", "USC00081641", "USC00081651", "USC00081978", "USC00082008",
"USC00082046", "USC00082150", "USC00082229", "USC00082288", "USC00082298",
"USC00082391", "USC00082418", "USC00082441", "USC00082850", "USC00082915",
"USC00082944", "USC00083020", "USC00083153", "USC00083163", "USC00083168",
"USC00083207", "USC00083209", "USC00083470", "USC00083874", "USC00083909",
"USC00083956", "USC00083986", "USC00084050", "USC00084095", "USC00084210",
"USC00084289", "USC00084320", "USC00084366", "USC00084394", "USC00084412",
"USC00084461", "USC00084625", "USC00084662", "USC00084731", "USC00084802",
"USC00085076", "USC00085099", "USC00085184", "USC00085275", "USC00085359",
"USC00085377", "USC00085539", "USC00085612", "USC00085667", "USC00085879",
"USC00085895", "USC00085973", "USC00086065", "USC00086078", "USC00086129",
"USC00086240", "USC00086315", "USC00086406", "USC00086414", "USC00086618",
"USC00086657", "USC00086764", "USC00086767", "USC00086828", "USC00086842",
"USC00086999", "USC00087020", "USC00087025", "USC00087205", "USC00087228",
"USC00087261", "USC00087304", "USC00087397", "USC00087429", "USC00087760",
"USC00087826", "USC00087851", "USC00087869", "USC00087886", "USC00087982",
"USC00088368", "USC00088529", "USC00088620", "USC00088756", "USC00088782",
"USC00088824", "USC00088942", "USC00089120", "USC00089176", "USC00089219",
"USC00089401", "USC00089430", "USC00089566", "USC00089640", "USC00089795",
"USR0000FBLO", "USR0000FCAC", "USR0000FCEN", "USR0000FCHE", "USR0000FLSU",
"USR0000FMER", "USR0000FMIL", "USR0000FNAV", "USR0000FOAS", "USR0000FOCH",
"USR0000FOLU", "USR0000FRAC", "USR0000FSAN", "USR0000FSTM", "USR0000FSUM",
"USR0000FWIL", "USW00003818", "USW00003853", "USW00012812", "USW00012815",
"USW00012816", "USW00012818", "USW00012819", "USW00012832", "USW00012833",
"USW00012834", "USW00012835", "USW00012836", "USW00012838", "USW00012839",
"USW00012841", "USW00012842", "USW00012843", "USW00012844", "USW00012849",
"USW00012850", "USW00012854", "USW00012871", "USW00012873", "USW00012876",
"USW00012882", "USW00012885", "USW00012888", "USW00012894", "USW00012895",
"USW00012896", "USW00012897", "USW00013884", "USW00013889", "USW00013899",
"USW00053847", "USW00053853", "USW00053860", "USW00092805", "USW00092806",
"USW00092809", "USW00092811", "USW00092821", "USW00093805", "USW00093837",
"USW00093841")

Related

Multiple Changepoint Analysis: penalty and significance

I am analyzing changes in unique users' ratings for different movies in time. In order to find significant changepoints in time, I am using the 'changepoint' package and the PELT method.
I understand that there are different types of penalties, however, I
am still unsure which one to use.
I tried to make an elbow plot to see the optimal number of changes,
but somehow it does not work. Here is what I have so far, based on,
for example, the movie "Inception".
Also, are all changepoints significant? Is there a way to prove
significance?
My data: timestamp_date = date; cummean = all ratings for the day:
timestamp_date cummean
18-07-2010 4.15384615
19-07-2010 4.23809524
20-07-2010 4.23880597
21-07-2010 4.24390244
22-07-2010 4.19387755
23-07-2010 4.21186441
24-07-2010 4.23758865
25-07-2010 4.28804348
26-07-2010 4.32126697
27-07-2010 4.34063745
28-07-2010 4.36330935
29-07-2010 4.35521886
30-07-2010 4.35448916
31-07-2010 4.34005764
1-08-2010 4.34741144
2-08-2010 4.35604113
3-08-2010 4.34725537
4-08-2010 4.33073497
5-08-2010 4.34051724
6-08-2010 4.34114053
7-08-2010 4.3467433
8-08-2010 4.32909091
9-08-2010 4.32901554
10-08-2010 4.32171799
11-08-2010 4.32316119
12-08-2010 4.32375189
13-08-2010 4.32532751
14-08-2010 4.32932011
15-08-2010 4.32855191
16-08-2010 4.33266932
17-08-2010 4.33246415
18-08-2010 4.33312102
19-08-2010 4.32982673
20-08-2010 4.33212121
21-08-2010 4.33195755
22-08-2010 4.33198614
23-08-2010 4.33370913
24-08-2010 4.3342511
25-08-2010 4.33441208
26-08-2010 4.33439153
27-08-2010 4.33541018
28-08-2010 4.331643
29-08-2010 4.32954545
30-08-2010 4.32992203
31-08-2010 4.330468
1-09-2010 4.33002833
2-09-2010 4.32679739
3-09-2010 4.32763401
4-09-2010 4.33091568
5-09-2010 4.33081033
6-09-2010 4.3289358
7-09-2010 4.33072917
8-09-2010 4.33104631
9-09-2010 4.33347422
10-09-2010 4.33430962
11-09-2010 4.33251029
12-09-2010 4.33292782
13-09-2010 4.33360129
14-09-2010 4.33359936
15-09-2010 4.33307024
16-09-2010 4.33268025
17-09-2010 4.33256528
18-09-2010 4.33358548
19-09-2010 4.33247232
20-09-2010 4.33734088
21-09-2010 4.33758621
22-09-2010 4.34044715
23-09-2010 4.34026846
24-09-2010 4.33878505
25-09-2010 4.33542631
26-09-2010 4.33409836
27-09-2010 4.33268482
28-09-2010 4.3332256
29-09-2010 4.33451157
30-09-2010 4.33545108
1-10-2010 4.33470032
2-10-2010 4.33550995
3-10-2010 4.33374384
4-10-2010 4.33455882
5-10-2010 4.33638026
6-10-2010 4.33704819
7-10-2010 4.33871933
8-10-2010 4.33881579
9-10-2010 4.33718861
10-10-2010 4.33931725
11-10-2010 4.34020918
12-10-2010 4.33927545
13-10-2010 4.33714286
14-10-2010 4.33730835
My code:
inds <- seq(as.Date("2010-07-18"), as.Date("2010-10-14"), by = "day")
myts <- ts(inception$cummean, start = c(2010, as.numeric(format(inds[1], "%j"))), frequency = 365)
#single changepoint: method AMOC
cpt <- changepoint::cpt.meanvar(myts)
cpts(cpt)
cpts.ts(cpt)
param.est(cpt)
plot(cpt)
summary(cpt)
#multiple changepoints: method PELT
mcpt <- changepoint::cpt.meanvar(myts, method = "PELT")
cpts(mcpt)
cpts.ts(mcpt)
param.est(mcpt)
ncpts(mcpt)
plot(mcpt)
summary(mcpt)
Also, as I use a ts.object, I cannot convert the date to appear right when I plot cpt, what am I doing wrong?
Thank you!!

How to decompose this time series data correctly in R?

We are trying to decompose a time series in R and we are able to do it but the results do not look right.
Here's the data with time stamps:
"_time","dummy_data"
"2017-02-05T00:00:00.000-0500","205.472222"
"2017-02-05T01:00:00.000-0500","169.443611"
"2017-02-05T02:00:00.000-0500","156.011944"
"2017-02-05T03:00:00.000-0500","177.169722"
"2017-02-05T04:00:00.000-0500","219.049167"
"2017-02-05T05:00:00.000-0500","215.821667"
"2017-02-05T06:00:00.000-0500","214.983333"
"2017-02-05T07:00:00.000-0500","246.723889"
"2017-02-05T08:00:00.000-0500","343.308889"
"2017-02-05T09:00:00.000-0500","473.200278"
"2017-02-05T10:00:00.000-0500","390.223333"
"2017-02-05T11:00:00.000-0500","373.974444"
"2017-02-05T12:00:00.000-0500","639.402500"
"2017-02-05T13:00:00.000-0500","512.378611"
"2017-02-05T14:00:00.000-0500","428.824444"
"2017-02-05T15:00:00.000-0500","477.611944"
"2017-02-05T16:00:00.000-0500","534.378611"
"2017-02-05T17:00:00.000-0500","716.046944"
"2017-02-05T18:00:00.000-0500","470.218056"
"2017-02-05T19:00:00.000-0500","411.426389"
"2017-02-05T20:00:00.000-0500","393.147222"
"2017-02-05T21:00:00.000-0500","368.726389"
"2017-02-05T22:00:00.000-0500","357.958056"
"2017-02-05T23:00:00.000-0500","379.284722"
"2017-02-06T00:00:00.000-0500","273.403056"
"2017-02-06T01:00:00.000-0500","269.764167"
"2017-02-06T02:00:00.000-0500","233.650000"
"2017-02-06T03:00:00.000-0500","227.802222"
"2017-02-06T04:00:00.000-0500","313.731389"
"2017-02-06T05:00:00.000-0500","327.502778"
"2017-02-06T06:00:00.000-0500","333.327500"
"2017-02-06T07:00:00.000-0500","393.542778"
"2017-02-06T08:00:00.000-0500","659.569167"
"2017-02-06T09:00:00.000-0500","770.509444"
"2017-02-06T10:00:00.000-0500","1037.536667"
"2017-02-06T11:00:00.000-0500","935.926667"
"2017-02-06T12:00:00.000-0500","791.124722"
"2017-02-06T13:00:00.000-0500","903.093889"
"2017-02-06T14:00:00.000-0500","802.309167"
"2017-02-06T15:00:00.000-0500","792.085000"
"2017-02-06T16:00:00.000-0500","728.378056"
"2017-02-06T17:00:00.000-0500","740.647222"
"2017-02-06T18:00:00.000-0500","737.986111"
"2017-02-06T19:00:00.000-0500","502.763056"
"2017-02-06T20:00:00.000-0500","475.400556"
"2017-02-06T21:00:00.000-0500","522.482500"
"2017-02-06T22:00:00.000-0500","410.664722"
"2017-02-06T23:00:00.000-0500","370.423611"
"2017-02-07T00:00:00.000-0500","278.871667"
"2017-02-07T01:00:00.000-0500","290.182500"
"2017-02-07T02:00:00.000-0500","220.329167"
"2017-02-07T03:00:00.000-0500","252.641944"
"2017-02-07T04:00:00.000-0500","355.666667"
"2017-02-07T05:00:00.000-0500","273.100833"
"2017-02-07T06:00:00.000-0500","315.117778"
"2017-02-07T07:00:00.000-0500","359.764167"
"2017-02-07T08:00:00.000-0500","691.946944"
"2017-02-07T09:00:00.000-0500","941.796667"
"2017-02-07T10:00:00.000-0500","859.472222"
"2017-02-07T11:00:00.000-0500","949.285278"
"2017-02-07T12:00:00.000-0500","790.790833"
"2017-02-07T13:00:00.000-0500","952.915000"
"2017-02-07T14:00:00.000-0500","1136.490278"
"2017-02-07T15:00:00.000-0500","1175.359444"
"2017-02-07T16:00:00.000-0500","859.848889"
"2017-02-07T17:00:00.000-0500","718.357778"
"2017-02-07T18:00:00.000-0500","698.445278"
"2017-02-07T19:00:00.000-0500","630.867778"
"2017-02-07T20:00:00.000-0500","485.426389"
"2017-02-07T21:00:00.000-0500","571.723056"
"2017-02-07T22:00:00.000-0500","458.161944"
"2017-02-07T23:00:00.000-0500","336.733333"
"2017-02-08T00:00:00.000-0500","344.001111"
"2017-02-08T01:00:00.000-0500","315.671111"
"2017-02-08T02:00:00.000-0500","285.107778"
"2017-02-08T03:00:00.000-0500","281.013611"
"2017-02-08T04:00:00.000-0500","260.244722"
"2017-02-08T05:00:00.000-0500","233.998056"
"2017-02-08T06:00:00.000-0500","260.235833"
"2017-02-08T07:00:00.000-0500","362.811944"
"2017-02-08T08:00:00.000-0500","633.142500"
"2017-02-08T09:00:00.000-0500","872.285278"
"2017-02-08T10:00:00.000-0500","938.051389"
"2017-02-08T11:00:00.000-0500","951.735278"
"2017-02-08T12:00:00.000-0500","967.694444"
"2017-02-08T13:00:00.000-0500","960.494167"
"2017-02-08T14:00:00.000-0500","1039.334444"
"2017-02-08T15:00:00.000-0500","808.363889"
"2017-02-08T16:00:00.000-0500","661.919722"
"2017-02-08T17:00:00.000-0500","604.166944"
"2017-02-08T18:00:00.000-0500","464.267500"
"2017-02-08T19:00:00.000-0500","425.867500"
"2017-02-08T20:00:00.000-0500","537.951111"
"2017-02-08T21:00:00.000-0500","528.523611"
"2017-02-08T22:00:00.000-0500","401.029444"
"2017-02-08T23:00:00.000-0500","396.677778"
"2017-02-09T00:00:00.000-0500","263.640833"
"2017-02-09T01:00:00.000-0500","233.905278"
"2017-02-09T02:00:00.000-0500","202.222778"
"2017-02-09T03:00:00.000-0500","194.326944"
"2017-02-09T04:00:00.000-0500","208.162222"
"2017-02-09T05:00:00.000-0500","257.111667"
"2017-02-09T06:00:00.000-0500","277.464444"
"2017-02-09T07:00:00.000-0500","403.655000"
"2017-02-09T08:00:00.000-0500","700.535278"
"2017-02-09T09:00:00.000-0500","888.195278"
"2017-02-09T10:00:00.000-0500","690.172778"
"2017-02-09T11:00:00.000-0500","822.210556"
"2017-02-09T12:00:00.000-0500","801.144167"
"2017-02-09T13:00:00.000-0500","983.958056"
"2017-02-09T14:00:00.000-0500","1003.791111"
"2017-02-09T15:00:00.000-0500","1085.289722"
"2017-02-09T16:00:00.000-0500","740.004167"
"2017-02-09T17:00:00.000-0500","616.664444"
"2017-02-09T18:00:00.000-0500","473.841389"
"2017-02-09T19:00:00.000-0500","570.906944"
"2017-02-09T20:00:00.000-0500","568.685000"
"2017-02-09T21:00:00.000-0500","547.024722"
"2017-02-09T22:00:00.000-0500","369.073889"
"2017-02-09T23:00:00.000-0500","431.275833"
"2017-02-10T00:00:00.000-0500","211.516667"
"2017-02-10T01:00:00.000-0500","169.348611"
"2017-02-10T02:00:00.000-0500","185.133611"
"2017-02-10T03:00:00.000-0500","173.875278"
"2017-02-10T04:00:00.000-0500","250.226667"
"2017-02-10T05:00:00.000-0500","237.783056"
"2017-02-10T06:00:00.000-0500","247.450000"
"2017-02-10T07:00:00.000-0500","375.930278"
"2017-02-10T08:00:00.000-0500","605.365000"
"2017-02-10T09:00:00.000-0500","647.407500"
"2017-02-10T10:00:00.000-0500","714.873889"
"2017-02-10T11:00:00.000-0500","767.262778"
"2017-02-10T12:00:00.000-0500","643.721389"
"2017-02-10T13:00:00.000-0500","653.969722"
"2017-02-10T14:00:00.000-0500","656.156111"
"2017-02-10T15:00:00.000-0500","763.260833"
"2017-02-10T16:00:00.000-0500","579.947778"
"2017-02-10T17:00:00.000-0500","734.142500"
"2017-02-10T18:00:00.000-0500","636.389722"
"2017-02-10T19:00:00.000-0500","360.105833"
"2017-02-10T20:00:00.000-0500","438.675278"
"2017-02-10T21:00:00.000-0500","420.990833"
"2017-02-10T22:00:00.000-0500","343.326111"
"2017-02-10T23:00:00.000-0500","293.787778"
"2017-02-11T00:00:00.000-0500","282.809444"
"2017-02-11T01:00:00.000-0500","249.653889"
"2017-02-11T02:00:00.000-0500","163.781111"
"2017-02-11T03:00:00.000-0500","245.236111"
"2017-02-11T04:00:00.000-0500","284.649444"
"2017-02-11T05:00:00.000-0500","337.534167"
"2017-02-11T06:00:00.000-0500","258.772222"
"2017-02-11T07:00:00.000-0500","322.805833"
"2017-02-11T08:00:00.000-0500","380.436667"
"2017-02-11T09:00:00.000-0500","523.488056"
"2017-02-11T10:00:00.000-0500","478.361111"
"2017-02-11T11:00:00.000-0500","422.119722"
"2017-02-11T12:00:00.000-0500","425.315000"
"2017-02-11T13:00:00.000-0500","465.892222"
"2017-02-11T14:00:00.000-0500","412.729167"
"2017-02-11T15:00:00.000-0500","493.920000"
"2017-02-11T16:00:00.000-0500","381.506667"
"2017-02-11T17:00:00.000-0500","458.291667"
"2017-02-11T18:00:00.000-0500","433.393611"
"2017-02-11T19:00:00.000-0500","415.926389"
"2017-02-11T20:00:00.000-0500","349.008056"
"2017-02-11T21:00:00.000-0500","353.280000"
"2017-02-11T22:00:00.000-0500","399.022778"
"2017-02-11T23:00:00.000-0500","316.480556"
"2017-02-12T00:00:00.000-0500","252.727222"
"2017-02-12T01:00:00.000-0500","274.278333"
"2017-02-12T02:00:00.000-0500","269.609444"
"2017-02-12T03:00:00.000-0500","221.645278"
"2017-02-12T04:00:00.000-0500","294.641389"
"2017-02-12T05:00:00.000-0500","347.502222"
"2017-02-12T06:00:00.000-0500","313.468333"
"2017-02-12T07:00:00.000-0500","330.429722"
"2017-02-12T08:00:00.000-0500","369.703333"
"2017-02-12T09:00:00.000-0500","518.679167"
"2017-02-12T10:00:00.000-0500","542.199167"
"2017-02-12T11:00:00.000-0500","475.780833"
"2017-02-12T12:00:00.000-0500","419.468056"
"2017-02-12T13:00:00.000-0500","447.899444"
"2017-02-12T14:00:00.000-0500","526.429722"
"2017-02-12T15:00:00.000-0500","517.046111"
"2017-02-12T16:00:00.000-0500","515.500833"
"2017-02-12T17:00:00.000-0500","631.053056"
"2017-02-12T18:00:00.000-0500","708.575000"
"2017-02-12T19:00:00.000-0500","453.120000"
"2017-02-12T20:00:00.000-0500","554.589444"
"2017-02-12T21:00:00.000-0500","453.551389"
"2017-02-12T22:00:00.000-0500","419.450556"
"2017-02-12T23:00:00.000-0500","328.177778"
"2017-02-13T00:00:00.000-0500","293.752500"
"2017-02-13T01:00:00.000-0500","246.943889"
"2017-02-13T02:00:00.000-0500","213.986944"
"2017-02-13T03:00:00.000-0500","219.086111"
"2017-02-13T04:00:00.000-0500","303.708611"
"2017-02-13T05:00:00.000-0500","353.969167"
"2017-02-13T06:00:00.000-0500","346.050833"
"2017-02-13T07:00:00.000-0500","470.292222"
"2017-02-13T08:00:00.000-0500","844.538056"
"2017-02-13T09:00:00.000-0500","1100.996667"
"2017-02-13T10:00:00.000-0500","1271.799167"
"2017-02-13T11:00:00.000-0500","1447.440000"
"2017-02-13T12:00:00.000-0500","1034.428611"
"2017-02-13T13:00:00.000-0500","1076.172222"
"2017-02-13T14:00:00.000-0500","1087.887222"
"2017-02-13T15:00:00.000-0500","1259.043333"
"2017-02-13T16:00:00.000-0500","1140.602778"
"2017-02-13T17:00:00.000-0500","1148.073889"
"2017-02-13T18:00:00.000-0500","761.544722"
"2017-02-13T19:00:00.000-0500","568.453056"
"2017-02-13T20:00:00.000-0500","574.121667"
"2017-02-13T21:00:00.000-0500","458.542500"
"2017-02-13T22:00:00.000-0500","495.431389"
"2017-02-13T23:00:00.000-0500","404.716111"
"2017-02-14T00:00:00.000-0500","412.116667"
"2017-02-14T01:00:00.000-0500","310.014444"
"2017-02-14T02:00:00.000-0500","236.658333"
"2017-02-14T03:00:00.000-0500","222.509167"
"2017-02-14T04:00:00.000-0500","315.510556"
"2017-02-14T05:00:00.000-0500","369.872778"
"2017-02-14T06:00:00.000-0500","334.670000"
"2017-02-14T07:00:00.000-0500","461.795000"
"2017-02-14T08:00:00.000-0500","753.752222"
"2017-02-14T09:00:00.000-0500","923.558333"
"2017-02-14T10:00:00.000-0500","1107.344722"
"2017-02-14T11:00:00.000-0500","1194.949722"
"2017-02-14T12:00:00.000-0500","937.735833"
"2017-02-14T13:00:00.000-0500","1068.374722"
"2017-02-14T14:00:00.000-0500","1145.634167"
"2017-02-14T15:00:00.000-0500","988.993889"
"2017-02-14T16:00:00.000-0500","1067.995278"
"2017-02-14T17:00:00.000-0500","927.699722"
"2017-02-14T18:00:00.000-0500","739.886389"
"2017-02-14T19:00:00.000-0500","667.679722"
"2017-02-14T20:00:00.000-0500","604.938333"
"2017-02-14T21:00:00.000-0500","543.166667"
"2017-02-14T22:00:00.000-0500","442.916944"
"2017-02-14T23:00:00.000-0500","373.767778"
"2017-02-15T00:00:00.000-0500","337.545833"
"2017-02-15T01:00:00.000-0500","259.629167"
"2017-02-15T02:00:00.000-0500","186.775556"
"2017-02-15T03:00:00.000-0500","212.818611"
"2017-02-15T04:00:00.000-0500","274.319722"
"2017-02-15T05:00:00.000-0500","308.578056"
"2017-02-15T06:00:00.000-0500","316.756389"
"2017-02-15T07:00:00.000-0500","417.723611"
"2017-02-15T08:00:00.000-0500","841.546944"
"2017-02-15T09:00:00.000-0500","1067.051111"
"2017-02-15T10:00:00.000-0500","1109.526389"
"2017-02-15T11:00:00.000-0500","1087.352222"
"2017-02-15T12:00:00.000-0500","1045.260000"
"2017-02-15T13:00:00.000-0500","1285.351389"
"2017-02-15T14:00:00.000-0500","1064.570833"
"2017-02-15T15:00:00.000-0500","1067.725556"
"2017-02-15T16:00:00.000-0500","1055.146111"
"2017-02-15T17:00:00.000-0500","1014.010833"
"2017-02-15T18:00:00.000-0500","720.152500"
"2017-02-15T19:00:00.000-0500","732.987778"
"2017-02-15T20:00:00.000-0500","758.056111"
"2017-02-15T21:00:00.000-0500","799.688611"
"2017-02-15T22:00:00.000-0500","766.204722"
"2017-02-15T23:00:00.000-0500","722.300000"
"2017-02-16T00:00:00.000-0500","507.248333"
"2017-02-16T01:00:00.000-0500","424.247778"
"2017-02-16T02:00:00.000-0500","390.718056"
"2017-02-16T03:00:00.000-0500","364.996944"
"2017-02-16T04:00:00.000-0500","383.408889"
"2017-02-16T05:00:00.000-0500","414.637778"
"2017-02-16T06:00:00.000-0500","349.056667"
"2017-02-16T07:00:00.000-0500","542.903889"
"2017-02-16T08:00:00.000-0500","878.198056"
"2017-02-16T09:00:00.000-0500","1137.686389"
"2017-02-16T10:00:00.000-0500","1277.625278"
"2017-02-16T11:00:00.000-0500","1184.350278"
"2017-02-16T12:00:00.000-0500","923.879444"
"2017-02-16T13:00:00.000-0500","1066.437500"
"2017-02-16T14:00:00.000-0500","1290.296667"
"2017-02-16T15:00:00.000-0500","1026.999722"
"2017-02-16T16:00:00.000-0500","949.582500"
"2017-02-16T17:00:00.000-0500","857.506111"
"2017-02-16T18:00:00.000-0500","831.030278"
"2017-02-16T19:00:00.000-0500","720.440556"
"2017-02-16T20:00:00.000-0500","492.239167"
"2017-02-16T21:00:00.000-0500","508.844722"
"2017-02-16T22:00:00.000-0500","559.846667"
"2017-02-16T23:00:00.000-0500","332.631389"
"2017-02-17T00:00:00.000-0500","349.220833"
"2017-02-17T01:00:00.000-0500","237.833333"
"2017-02-17T02:00:00.000-0500","202.662778"
"2017-02-17T03:00:00.000-0500","232.843889"
"2017-02-17T04:00:00.000-0500","316.059167"
"2017-02-17T05:00:00.000-0500","338.066667"
"2017-02-17T06:00:00.000-0500","363.631389"
"2017-02-17T07:00:00.000-0500","460.921944"
"2017-02-17T08:00:00.000-0500","764.931111"
"2017-02-17T09:00:00.000-0500","931.416944"
"2017-02-17T10:00:00.000-0500","1032.328611"
"2017-02-17T11:00:00.000-0500","1247.801111"
"2017-02-17T12:00:00.000-0500","1159.197500"
"2017-02-17T13:00:00.000-0500","1282.267222"
"2017-02-17T14:00:00.000-0500","1183.746667"
"2017-02-17T15:00:00.000-0500","992.880278"
"2017-02-17T16:00:00.000-0500","791.148611"
"2017-02-17T17:00:00.000-0500","599.060278"
"2017-02-17T18:00:00.000-0500","487.915556"
"2017-02-17T19:00:00.000-0500","492.801111"
"2017-02-17T20:00:00.000-0500","413.024167"
"2017-02-17T21:00:00.000-0500","632.193056"
"2017-02-17T22:00:00.000-0500","493.108611"
"2017-02-17T23:00:00.000-0500","424.018889"
"2017-02-18T00:00:00.000-0500","384.328056"
"2017-02-18T01:00:00.000-0500","310.441944"
"2017-02-18T02:00:00.000-0500","205.145556"
"2017-02-18T03:00:00.000-0500","205.454167"
"2017-02-18T04:00:00.000-0500","253.227500"
"2017-02-18T05:00:00.000-0500","312.188889"
"2017-02-18T06:00:00.000-0500","321.928889"
"2017-02-18T07:00:00.000-0500","406.977778"
"2017-02-18T08:00:00.000-0500","452.448889"
"2017-02-18T09:00:00.000-0500","502.578333"
"2017-02-18T10:00:00.000-0500","489.765278"
"2017-02-18T11:00:00.000-0500","540.568333"
"2017-02-18T12:00:00.000-0500","510.270000"
"2017-02-18T13:00:00.000-0500","456.691944"
"2017-02-18T14:00:00.000-0500","494.579722"
"2017-02-18T15:00:00.000-0500","502.795556"
"2017-02-18T16:00:00.000-0500","429.950556"
"2017-02-18T17:00:00.000-0500","428.196667"
"2017-02-18T18:00:00.000-0500","478.975833"
"2017-02-18T19:00:00.000-0500","362.479167"
"2017-02-18T20:00:00.000-0500","366.515000"
"2017-02-18T21:00:00.000-0500","400.625833"
"2017-02-18T22:00:00.000-0500","374.313056"
"2017-02-18T23:00:00.000-0500","310.666667"
We use the following code to load and decompose this time series:
library("forecast")
data <- read.csv("data.csv")
x <- msts(data, seasonal.periods=c(24,168))
decom <- decompose(x[,2], "multiplicative")
plot(decom)
The decomposition looks like this:
The 'observed' and 'seasonal' components looks almost identical, the 'trend' doesn't seem right since it is rising up too sharply, and the 'random' component looks constant.
So we are not sure if we made a mistake in decomposing or loading this time series in R. Is there another way of decomposing this time series so that it makes more sense or is correct? Should we be loading the data another way so that the time stamps get properly assigned to the data values?

How to access a particular sub-set of data in R Table

I have tabular (long format) data with a number of variables. I want to load the csv once and then access a particular sub-set later on from it. For example:
Blog,Region,Dim1
Individual,PK,-4.75
Individual,PK,-5.69
Individual,PK,-0.27
Individual,PK,-2.76
Individual,PK,-8.24
Individual,PK,-12.51
Individual,PK,-1.28
Individual,PK,0.95
Individual,PK,-5.96
Individual,PK,-8.81
Individual,PK,-8.46
Individual,PK,-6.15
Individual,PK,-13.98
Individual,PK,-16.43
Individual,PK,-4.09
Individual,PK,-11.06
Individual,PK,-9.04
Individual,PK,-8.56
Individual,PK,-8.13
Individual,PK,-14.46
Individual,PK,-4.21
Individual,PK,-4.96
Individual,PK,-5.48
Multiwriter,PK,-3.31
Multiwriter,PK,-5.62
Multiwriter,PK,-4.48
Multiwriter,PK,-6.08
Multiwriter,PK,-4.68
Multiwriter,PK,-6.92
Multiwriter,PK,-11.29
Multiwriter,PK,6.66
Multiwriter,PK,1.66
Multiwriter,PK,3.39
Multiwriter,PK,0.06
Multiwriter,PK,4.11
Multiwriter,PK,-1.57
Multiwriter,PK,1.33
Multiwriter,PK,-6.91
Multiwriter,PK,4.87
Multiwriter,PK,-10.87
Multiwriter,PK,6.25
Multiwriter,PK,-0.68
Multiwriter,PK,0.11
Multiwriter,PK,0.71
Multiwriter,PK,-3.8
Multiwriter,PK,-1.75
Multiwriter,PK,-5.38
Multiwriter,PK,1.24
Multiwriter,PK,-5.59
Multiwriter,PK,4.98
Multiwriter,PK,0.98
Multiwriter,PK,7.47
Multiwriter,PK,-5.25
Multiwriter,PK,-14.24
Multiwriter,PK,-1.55
Multiwriter,PK,-8.44
Multiwriter,PK,-7.67
Multiwriter,PK,5.85
Multiwriter,PK,6
Multiwriter,PK,-7.53
Multiwriter,PK,1.59
Multiwriter,PK,-9.48
Multiwriter,PK,-3.99
Multiwriter,PK,-5.82
Multiwriter,PK,1.62
Multiwriter,PK,-4.14
Multiwriter,PK,1.06
Multiwriter,PK,4.52
Multiwriter,PK,-5.6
Multiwriter,PK,-3.38
Multiwriter,PK,4.82
Multiwriter,PK,0.76
Multiwriter,PK,-4.95
Multiwriter,PK,-2.05
Column,PK,1.64
Column,PK,5.2
Column,PK,2.8
Column,PK,1.93
Column,PK,2.36
Column,PK,4.77
Column,PK,-1.92
Column,PK,-2.94
Column,PK,4.58
Column,PK,2.98
Column,PK,9.07
Column,PK,8.5
Column,PK,1.23
Column,PK,8.97
Column,PK,4.1
Column,PK,7.25
Column,PK,0.02
Column,PK,-3.48
Column,PK,1.01
Column,PK,2.7
Column,PK,-2.32
Column,PK,3.22
Column,PK,-2.37
Column,PK,-13.28
Column,PK,-4.36
Column,PK,2.91
Column,PK,4.4
Column,PK,-5.07
Column,PK,-10.24
Column,PK,12.8
Column,PK,1.92
Column,PK,13.24
Column,PK,12.32
Column,PK,12.7
Column,PK,9.95
Column,PK,12.11
Column,PK,7.63
Column,PK,11.09
Column,PK,13.04
Column,PK,12.06
Column,PK,9.49
Column,PK,8.64
Column,PK,10.05
Column,PK,6.4
Column,PK,9.64
Column,PK,3.53
Column,PK,4.78
Column,PK,9.54
Column,PK,8.49
Column,PK,2.56
Column,PK,8.82
Column,PK,-3.59
Column,PK,-3.31
Column,PK,10.05
Column,PK,-0.28
Column,PK,-0.5
Column,PK,-6.37
Column,PK,2.97
Column,PK,4.49
Column,PK,9.14
Column,PK,4.5
Column,PK,8.6
Column,PK,6.76
Column,PK,3.67
Column,PK,6.79
Column,PK,5.77
Column,PK,10.5
Column,PK,1.57
Column,PK,9.47
Individual,US,-9.85
Individual,US,-2.73
Individual,US,-0.32
Individual,US,-0.94
Individual,US,-7.51
Individual,US,-8.21
Individual,US,-7.33
Individual,US,-5.1
Individual,US,-1.58
Individual,US,-2.49
Individual,US,-1.36
Individual,US,-5.76
Individual,US,-0.48
Individual,US,-3.38
Individual,US,2.42
Individual,US,-1.71
Individual,US,-2.17
Individual,US,-2.81
Individual,US,-0.64
Individual,US,-8.88
Individual,US,-1.53
Individual,US,-1.42
Individual,US,-17.89
Individual,US,7.1
Individual,US,-4.12
Individual,US,-0.83
Individual,US,2.05
Individual,US,-5.87
Individual,US,-0.15
Individual,US,5.78
Individual,US,-1.96
Individual,US,1.77
Individual,US,-0.67
Individual,US,-10.23
Individual,US,3.37
Individual,US,-1.18
Individual,US,6.94
Individual,US,-3.86
Individual,US,2.21
Individual,US,-11.64
Individual,US,-14.71
Individual,US,-12.74
Individual,US,-6.24
Individual,US,-13.64
Individual,US,-8.53
Individual,US,-10.4
Individual,US,-6.24
Individual,US,-12.15
Individual,US,-15.96
Multiwriter,US,11.27
Multiwriter,US,3.51
Multiwriter,US,4.05
Multiwriter,US,3.81
Multiwriter,US,8.56
Multiwriter,US,6.36
Multiwriter,US,-8.99
Multiwriter,US,3.36
Multiwriter,US,3.18
Multiwriter,US,-5.22
Multiwriter,US,-8.61
Multiwriter,US,-9.02
Multiwriter,US,-6.32
Multiwriter,US,0.53
Multiwriter,US,11.03
Multiwriter,US,-5.7
Multiwriter,US,4
Multiwriter,US,-3.55
Multiwriter,US,2.79
Multiwriter,US,4.61
Multiwriter,US,-3.8
Multiwriter,US,-9.62
Multiwriter,US,-8.37
Multiwriter,US,-2.18
Multiwriter,US,-1.64
Multiwriter,US,-9.99
Multiwriter,US,-1.44
Multiwriter,US,-4.45
Multiwriter,US,-7.84
Multiwriter,US,-11.6
Multiwriter,US,-2.71
Multiwriter,US,1.2
Multiwriter,US,-6.44
Multiwriter,US,-2.64
Multiwriter,US,-11.59
Multiwriter,US,-5.9
Multiwriter,US,-3.78
Multiwriter,US,-14.99
Multiwriter,US,1.32
Multiwriter,US,-6.55
Multiwriter,US,0.92
Multiwriter,US,-5.61
Multiwriter,US,-14.16
Multiwriter,US,-10.03
Multiwriter,US,-7.08
Multiwriter,US,0.62
Multiwriter,US,-5.43
Multiwriter,US,-1.11
Multiwriter,US,-11.37
Multiwriter,US,-13.37
Multiwriter,US,-12.71
Multiwriter,US,1.86
Multiwriter,US,14.11
Multiwriter,US,-5.24
Multiwriter,US,-6.77
Multiwriter,US,-4.79
Multiwriter,US,-6.22
Multiwriter,US,3.66
Multiwriter,US,-2.65
Multiwriter,US,-2.87
Multiwriter,US,-12.32
Multiwriter,US,-7.48
Multiwriter,US,-4.84
Multiwriter,US,0.44
Column,US,8.93
Column,US,10.29
Column,US,8.31
Column,US,5.88
Column,US,8.87
Column,US,-2.9
Column,US,3.71
Column,US,8.43
Column,US,1.47
Column,US,3.05
Column,US,-1.78
Column,US,1.14
Column,US,7.2
Column,US,5.22
Column,US,5.53
Column,US,8.14
Column,US,-2.22
Column,US,0.89
Column,US,2.5
Column,US,6.77
Column,US,3.63
Column,US,2.86
Column,US,3.7
Column,US,7.52
Column,US,3.12
Column,US,0
Column,US,0.28
Column,US,6.86
Column,US,-0.32
Column,US,2.92
Column,US,-1.14
Column,US,-1.11
Column,US,4.42
Column,US,4.37
Column,US,1.09
Column,US,-3.66
Column,US,7.09
Column,US,-11.02
Column,US,-0.78
Column,US,8.44
Column,US,4.88
Column,US,-3.9
Column,US,-0.21
Column,US,6.48
Column,US,4.49
Column,US,-8.89
Column,US,-0.73
Column,US,1.76
Column,US,-4.31
Column,US,4.63
Column,US,8.91
Column,US,3.55
Column,US,6.69
Column,US,-4.45
Column,US,9.82
Column,US,6.79
Column,US,1.84
Column,US,8.97
Column,US,2.38
Column,US,4.68
Column,US,9.23
Column,US,2.85
Column,US,4.19
Column,US,2.43
Column,US,5.48
Column,US,-1.08
Column,US,7.47
Column,US,3.13
Column,US,-0.42
Column,US,-0.71
Column,US,6.51
Column,US,6.34
Column,US,3.94
Column,US,5.46
Column,US,0.39
Column,US,8.15
Column,US,7.99
Column,US,6.26
Column,US,7.91
Column,US,14.18
Column,US,7.41
Column,US,7.16
Column,US,5.6
Column,US,7.51
Column,US,6.24
Column,US,3.67
Column,US,3.84
Column,US,2.37
Column,US,-3.5
Column,US,5.02
Column,US,-6.04
Column,US,5.36
Column,US,1.98
Column,US,7.79
Column,US,0.02
Column,US,-1.9
Column,US,-2.81
Column,US,10.69
Column,US,1.65
Column,US,8.19
Column,US,1.92
How can I access values related to 'Column' with 'US' subset from 'Dim1'?
I have tried to read about 'data frame, table, factor' and 'matrix' data types in R, but I could not find help how to access a subset of a complex table like this. (My real data includes additional vectors of numerical values like Dim1... i.e. Dim2, Dim3, Dim4, Dim5). But that should be the same in principle so I have not included that in this example.
I assume you want to select only the rows which have 'Column' and 'US'.
If so you can select the subset using:
data[data[,1]=='Column' & data[,2]=='US',]

unable to draw contour in R for temperature data

I have my data in a csv file in the given format.
csv file data
Latitude,Longitude,Temperature
20,84.01,15.93913043
28.48,77.13,16.62857143
28.68,77.2,17.81333333
31.32,78.16,2.472222222
31.531,77.112,5.228
28.11,77,21.85
31.5,77.09,7.910526316
31.43,76.57,11.444
28.7,77.15,17.708
30.55,77.35,15.30526316
26.95,78.96,16.46818182
27.44,79.39,15.74090909
26.58,81.59,15.90952381
25.33,80.43,18.465
29.45,77.34,14.15238095
20.42,86.47,19.83181818
29.52,75.5,14.135
24.17,72.43,20.065
25.1,76.19,18.59444444
30.975,76.517,14.88421053
28.8,76.13,16.05
29.54,75.04,15.295
24.32,72.3,18.84782609
23.86,72.13,20.49444444
30.19,74.95,13.996
22.36,73.16,22.365
30.78,75.84,13.75652174
21.86,73.52,24.725
21.5,70.44,22.812
21.36,69.75,22.33125
30.32,78.05,15.35
20.92,72.89,21.3
17.69,74.02,23.45
28.3278,77.2467,17.87857143
20.17,79.98,21.11428571
24,76.73,23.67857143
22.76,74.59,19.97619048
22.03,74.97,20.85
29.57,80.23,12.70869565
29.95,79.9,13.425
25.92,83.56,16.67
27.6,81.58,15.128
24.68,78.4,19.1
18.11,76.02,22.84285714
20.39,78.11,24.98571429
24.57,80.82,23.35714286
21.283,76.198,22.98235294
21.81,80.18,20.16666667
24.5,81.3,16.22857143
22.09,82.17,18.93636364
30.35,76.87,14.77
19.7,81.7,19.98823529
18.9,81.35,19.16956522
28.9917,77.701,15.43636364
28.39,77.83,15.745
27.58,77.98,16.52631579
27.03,79.92,17.40526316
26.57,80.48,12.67
25.17,80.91,24.75
26.55,79.55,17.12727273
22.443,77.03,18.825
30.19,78.18,15.72857143
29.87,77.88,14.75454545
26.54,81.83,15.75416667
29.93,77.97,12.96666667
26.127,81.94,17.54666667
26.43,82.57,16.63684211
29.34,80.09,11.82631579
27.14,83.53,15.82
21.1,86.5,19.82
20.25,85.82,21.31
21.13,86.57,19.352
20.23,86.18,19.52173913
20.46,85.9,20.74
27.17,78.03,17.292
20.83,84.33,19.224
21.89,84.03,19.47142857
20.01,83.01,20.295
19,83.01,21.24285714
18.53,73.83,22.47142857
18.81,82.71,19.04545455
18.01,82.01,20.73076923
25,84.01,16.952
25.03,85.6,18.48125
19.92,83.16,19.975
26.21,84.35,16.15454545
26.58,84.38,16.1952381
25.73,85.23,15.9375
26.38,85.73,16.39
25.98,85.66,16.176
30.48,78.05,8.985
18.35,81.88,21.736
26.54,85.72,16.53043478
26,85.01,16.104
26.9,75.8,18.97272727
25.92,86.8,16.01904762
26.42,74.62,21.04545455
24.87,85.53,14.9
24.8,85.04,16.236
25.91,86.55,16.17
25.3,83,20.13333333
25.52,87.57,17.13181818
25.37,86.48,17.56190476
25.01,86,16.42727273
26.9,76.35,18.836
25.23,87.03,15.3875
26.07,76.37,17.324
25.41,75.65,18.03684211
25.12,75.93,17.93333333
19.65,78.52,21.51052632
24.58,76.13,19.8
26.16,75.78,19.24285714
24.9,74.61,18.74583333
18.56,77.88,23.68571429
18.83,78.93,22.75238095
17.01,78.97,21.63684211
18.43,79.08,22.78181818
17.21,77.58,22.36363636
26.51,85.28,15.988
18.01,79.6,24.295
16.5,78.23,22.368
28.62,77.27,17.135
15.45,78.46,24.09444444
16.85,79.47,23.58571429
16.35,80.43,23.988
17.62,74.07,22.97777778
16.36,80.84,22.976
14.68,77.67,23.62
17.87,82.34,19.12
17.7,83,21.62083333
14.11,78.15,23.52352941
14.43,78.8,23.92857143
17.24,81.1,22.6
23.55,74.44,26.72
23.51,74.38,19.105
28.28,75.12,18.33333333
12.38,78.21,23.22857143
28.35,75.58,16.25714286
11.33,76.8,15.97391304
13.15,80.23,23.65263158
13.63,79.73,22.688
12.71,77.81,21.03809524
11.62,79.53,24.01818182
13.61,79.34,22.35454545
11.01,76.94,24.765
11.37,76.63,14.824
13.25,80.31,26.384
11.13,79.07,25.87
11.22,78.87,24.86
26.25,82,16.25217391
10.77,76.7,26.32
11.15,78.15,26.03888889
10.53,76.28,27.46666667
24.57,73.7,9.8
9.62,76.42,28.135
12.95,78.25,22.26111111
23.86,73.86,20.24
12.97,77.18,23.35652174
9.55,77.934,26.18636364
10.117,77.583,24.93157895
13.663,76.916,22.21363636
9.2,77.88,26.98
8.43,76.99,26.33809524
8.73,77.7,27.02380952
11.26,75.77,28.36470588
8.43,77.3,26.47619048
11.0617,76.21,21.59
12.15,76.8,22.73809524
13.34,75.8,20.49047619
11.91,76.93,23.37619048
25.79,73.3,18.55652174
13.72,75.72,22.75263158
12.42,75.73,19.85
26.8,75.8,18.80416667
25.75,71.4,24.05
25.38,72.5,22.38
27.9,78.07,17.15789474
26.12,91.82,18.00555556
14.611,74.846,21.89
12.65,74.96,25.74736842
16.18,77.32,24.73888889
15.48,74.98,22.80909091
27.58,75.13,17.195
27.15,73.78,21.04166667
17.35,76.8,23.78888889
27.93,74.98,17.32105263
26.351,92.633,17.57142857
25.87,93.43,15.88
14.78,75.33,23.655
15.9,75.55,23.05454545
16.98,75.75,23.73333333
27.53,76.6,17.01052632
26.44,89.94,15.684
26.35,90.65,18.98
26.48,90.9,15.688
29.49,73.5,13.752
14.03,77.27,23.605
29.93,73.88,14.30588235
26.65,91.33,16.59565217
16.15,75.6,19.57692308
13.96,75.56,22.95714286
26.71,93.13,15.95714286
26.72,77.89,19.03846154
25.11,76.47,19.04444444
26.16,90.63,16.86818182
26.51,93.96,16.56956522
26.467,90.283,16.615
27.2,77.46,15.84545455
26.72,94.18,16.61
26.55,77,18.58695652
27.467,95.02,16.452
10.08,77.05,16.04
25.36,74.63,19.18571429
14.283,74.45,25.65238095
24.6,92.55,18.965
25.56,91.86,11.03478261
24.85,92.3,23.05
25.454,92.2069,12.044
9.834,76.95,22.456
28.333,79.417,15.99090909
27.71,81.91,14.88571429
25.87,84.13,12.81666667
26.78,78.98,20.1
26.33,79.97,17.7125
25.68,91.92,14.98888889
25.2,90.63,19.11578947
25.52,91.27,10.316
26.25,81.37,17.04210526
24.58,72.7,14.35
26.95,94.62,17.43333333
27.48,95.31,16.108
23.53,84.81,16.07619048
26.97,93.87,15.712
25.5,90.58,16.09473684
23.78,85.88,17.42631579
24.83,87.2,17.484
25.23,86.65,22.075
27.47,94.55,17.31052632
24.5,87.81,17.99130435
26.52,90.48,16.925
24.49,86.66,21.56875
17.43,78.47,23.636
24.2,86.3,16.83
24.16,83.8,16.635
22.47,88.09,18.27777778
24.8,92.78,18.168
22.69,86.43,17.15238095
22.27,87.92,19.71666667
29.46,79.65,9.25
22.3,87.3,18.97
22.36,88.43,18.58571429
22.662,88.873,19.12
22.97,88.48,21.24545455
23.4,88.49,17.99166667
23.53,91.46,17.92
32.37,75.55,14.44583333
23.21,87.88,19.11666667
32.65,74.8,13.45454545
23.24,87.04,18.892
23.91,87.52,19.42272727
31.18,77.13,4.424
24.092,88.27,21.4
25.62,88.14,17.50555556
31.33,75.33,13.91428571
23.8,91.27,19.10555556
26.52,88.72,13.65625
24.4,89.39,15.97826087
34.05,74.8,3.419047619
34.14,74.87,2.961904762
25.31,88.76,17.65263158
34.06,74.71,3.036363636
27.07,88.46,13.75652174
27.15,88.4,11.696
24.07,91.61,18.56842105
34.35,74.4,1.118181818
25.18,93.01,18.8
33.888,74.9808,5.125
33.64,74.94,1.635
23.43,85.3,17.4
24.18,91.82,22.1
23.48,93.3,14.836
24.208,92.675,18.988
23.95,92.49,18.305
33.22,75.26,7.57
23.33,92.83,17.485
22.5055,92.895,18.21578947
32.9,75.167,11.42
22.95,92.93,16.78
22.48,92.98,19.40454545
26.72,92.08,16.804
18.22,74.48,23.43333333
17.26,74.42,17.07647059
30.15,75.41,17.36666667
31.63,74.83,14.29444444
31.46,77.22,5.661904762
30.73,76.8,15.395
31.32,75.3,13.80769231
30.91,74.66,13.28947368
20.76,73.69,23.83333333
31.37,74.97,12.724
31.38,76.024,14.865
20.4,72.833,20.672
23.303,70.36,20.628
31.39,75.36,14.52142857
21.144,72.75,24.92222222
23.37,68.54,19.37222222
20.8,70.7,22.295
20.143,74.794,26.94444444
18.97,73.04,24.73157895
18.33,73.79,22.23684211
21.02,75.53,23.15833333
28.47,77.03,21.1
17.67,75.92,24.94545455
19.03,73.17,24.74615385
22.94,79.22,17.4
25.688,78.4419,18.9
22.94,81.08,15.76818182
22.6,82.13,18.308
21.1,81.034,21.95
21.97,81.24,20.3375
22.37,82.733,17.77083333
21.23,81.7,14.96428571
25.35,81.3,16.92
26.79,82.72,18.1125
26.48,83.77,16.86666667
29.36,79.46,9.733333333
25.92,84.13,16.616
28.98,79.4,16.068
25.72,82.68,16.572
25.17,82.6,16.175
29.62,79.62,13.245
30.7,76.9,16.096
30.36,75.53,13.78888889
22.8,73.22,20.07083333
22.58,72.28,20.46
22.73,72.88,23.5875
23.27,72.65,21.43888889
30.36,76.45,13.97
22.88,74.23,21.42
17.69,74.02,20.988
18.53,73.8,21.98095238
28.1,77,14.965
28.08,76.59,17.8
31.1,77.17,6.628571429
28.28,76.15,17.94
30.1,77.28,14.07777778
29.68,77,13.628
29.7,77.03,14.21764706
29.38,77,12.85384615
28.611,76.651,15.08947368
28.8836,76.619,15.695
29.78,76.4,13.67
31.35,76.7525,13.14347826
31.45,76.26,13.85238095
28.66,77.31,17.71578947
29.58,76.51,14.625
29.3,75.45,15.28421053
29.068,75.476,16.05263158
28.63,77.15,16.575
28.8,76.97,15.12
30.90444,76.96,8.48
30.89916,76.96,12.392
31.5858,77.0748,6.884
32.3521,76.0608,7.844
32.1994,76.3249,11.67777778
28.58,76.9,15.6
29.13,75.7,15.608
30.2,75.88,14.72857143
31.09,76.38,15.6
31.13,76.12,14.7
30.6,76.1,13.49090909
30.67,74.74,13.825
21.7,73.01,14.45
21.73,72.55,23.42352941
32.05,75.42,13.04736842
30.62,76.41,13.49090909
31.6,75.98,16.1
20.54,73.16,22.70833333
22.73,71.62,24.21538462
28.63,77,17.245
19.18,72.98,27.00666667
20.9,74.8,23.6
23.83,73,21.71333333
21.16,73.79,23.51578947
28.63,77.36,16.836
28.63,77.37,17.252
28.23,77.18,15.85454545
22.34,70.91,21.075
21.37,74.23,24.24210526
19.09,74.75,21.21818182
19.36,75.95,23.3047619
16,73.7,25.14166667
16.67,74.16,22.89545455
18.4,76.56,23.275
15.48,73.91,26.81764706
19.85,75.87,21
20.94,77.78,23.285
18.72,76.36,23.89375
19.73,77.15,21.85263158
20.13,77.13,25.08125
20.7,77.65,20.05
21.16,79.65,21.32
21.49,80.15,18.30416667
22.3,79.67,23.19090909
26.4772,77.9866,17.328
26.5727,78.81,16.856
22.0683,79.5488,16.036
24.5972,77.75,18.8625
24.42,74.8708,18.93809524
24.06,75.1,18.93333333
22.88,84.56,16.75
23.444,75.044,18.97916667
22.7,75.89,20.97
20.53,76.19,23.49
21.82,75.62,22.50952381
23.83,78.69,26.7875
23.18,77.06,20.295
25.03,79.5,18.79
23.82,79.4,17.095
25.67,76.69,21.26
22.314,74.353,19.064
22.056,78.94,16.83333333
21.86,77.937,19.58333333
23.21,79.96,17.56190476
22.6,80.3,16.14761905
23.28,81.33,16.37142857
24.73,80.21,19.6625
23.525,80.84,17.63888889
24.41,81.86,18.38461538
23.09,83.14,15.60666667
24.07,82.61,16.95555556
23.12,81.7,17.71111111
21.88,83.4,19.548
23.515,77.81,20.57142857
22.58,81.13,19.17368421
21.103,82.083,20.92380952
20.66,81.53,20.27647059
20.25,81.5,20.64444444
30.756,75.163,12.795
18.8,80.8,21.0952381
28.01,79.11,16.25
27.55,78.65,15.1
27.22,79.03,17.38947368
16.98,73.32,24.70526316
30.05,79,8.456
30.74,76.73,16.32727273
25.21,82.27,22.54
19.8,85.83,21.5952381
20.84,86.32,20.155
22.03,84.05,19.05217391
21.33,83.62,19.915
20.12,85.08,19.904
21.61,85.56,18.728
20.83,85.1,19.656
21.36,83.88,18.896
20.52,86.43,19.76190476
19.3,84.8,22.65333333
19.25,82.54,19.03333333
24.95,84,18.05
23.55,83.96,16.288
25.0286,73.89,18.44117647
11.28,76.23,25.91666667
26.26,72.99,18.52
15.42,75.63,23.7
22.9,88.37,16.58095238
27.28,88.23,10.93333333
26.02,94.53,10.45
I tried drawing a contour using contour(), contourplot() etc, I am not sure how to make my data regular to get a contour . I tried akima interp() but getting error given below. not sure what that means and how to correct my data to get a contour.
*Error in is.finite(x) : default method not implemented for type 'list'*
someone please help me out. Thanks.
This works for me (by the way, dumping this size data file, even though it's only moderate-sized, is kind of a pain for responders: if you can post it somewhere that's easier. I had to save the HTML page source and extract the info that way, as it was too big for me to cut & paste from the clipboard):
X <- read.csv("tempcontour.txt")
library(akima)
## needed to specify the 'duplicate' argument (see ?interp)
interp1 <- with(X,interp(Latitude,Longitude,Temperature,
duplicate="mean"))
names(interp1) <- colnames(X) ## assumes colnames are in Lat/Long/Temp order
png("interp1.png")
with(interp1,contour(Longitude,Latitude,Temperature,
ylab="Latitude",xlab="Longitude"))
dev.off()

R: Plot ARC/INFO Generate File

I have an ARC/INFO generate file whose contents look like:
3594 -124.049541 44.429077
-123.381222 44.530192
-123.479913 44.625517
-123.578917 44.720704
-123.678234 44.815755
-123.777866 44.910669
-123.946044 44.885032
-124.114074 44.858987
-124.281949 44.832529
-124.449663 44.805654
-124.516511 44.684660
-124.583091 44.563597
-124.649404 44.442465
-124.715451 44.321261
-124.615376 44.227772
-124.515601 44.134147
-124.416125 44.040385
-124.316948 43.946486
-124.151513 43.973082
-123.985926 43.999247
-123.820193 44.024987
-123.654322 44.050307
-123.586447 44.170362
-123.518307 44.290360
-123.449899 44.410303
-123.381222 44.530192
END
3595 -123.103772 45.009223
-122.427717 45.101578
-122.525757 45.198252
-122.624122 45.294789
-122.722814 45.391191
-122.821833 45.487459
-122.992014 45.464007
-123.162072 45.440175
-123.332002 45.415959
-123.501798 45.391355
-123.571234 45.271264
-123.640389 45.151121
-123.709266 45.030923
-123.777866 44.910669
-123.678234 44.815755
-123.578917 44.720704
-123.479913 44.625517
-123.381222 44.530192
-123.213811 44.554460
-123.046278 44.578334
-122.878629 44.601816
-122.710869 44.624913
-122.640504 44.744148
-122.569859 44.863337
-122.498931 44.982480
-122.427717 45.101578
END
3676 -122.989567 44.147495
-122.323040 44.238368
-122.419523 44.335217
-122.516322 44.431923
-122.613437 44.528488
-122.710869 44.624913
-122.878629 44.601816
-123.046278 44.578334
-123.213811 44.554460
-123.381222 44.530192
-123.449899 44.410303
-123.518307 44.290360
-123.586447 44.170362
-123.654322 44.050307
-123.556277 43.955264
-123.458534 43.860080
-123.361093 43.764751
-123.263953 43.669279
-123.098838 43.693189
-122.933613 43.716694
-122.768285 43.739802
-122.602857 43.762515
-122.533309 43.881546
-122.463492 44.000532
-122.393403 44.119472
-122.323040 44.238368
END
END
My strategy is to read in the file generating a list of latitude-longitude points and beginning a new unique group id every time I encounter an END. I'll then plot using ggplot" andgeom_polygon".
Alas, I'm not sure how to efficiently accomplish the reading of the file.
Any thoughts?
Read the spatial task view on CRAN and then use readOGR from the rgdal package to read into an sp class object. You'll need a GDAL/OGR install with ARCGEN format support, which despite being listed as 'compiled by default' Link I don't have on my system.
Failing that, open the file as a connection, read each line, build a Polygon, then Polygons and SpatialPolygons.
Here's a fairly sub-optimal but working function:
readUng <- function(f){
require(sp)
stream = file(f,"r")
first = readLines(stream,1)
bits = strsplit(first," ")[[1]]
polys = list();ids=NULL
while(TRUE){
id=bits[1] # label pt = bits[2],bits[3]
ids=c(ids,id)
coords=NULL
while(TRUE){
xy=readLines(stream,1)
if(xy=="END"){
break
}
coords=rbind(coords,strsplit(xy," ")[[1]])
}
polys[[length(polys)+1]] = Polygons(list(Polygon(matrix(as.numeric(coords[,2:3]),ncol=2))),ID=id)
lines = readLines(stream,1)
if(lines == "END"){
break
}
bits = strsplit(lines," ")[[1]]
}
return(SpatialPolygons(polys))
}
Now its a proper spatial data object, you can also give it a coordinate system (looks like lat-long to me, so epsg:4326, but only you know). Now you could modify all this to produce whatever ggplot wants, but if its spatial data then you should keep it as a spatial data class and ggplot should be made capable of dealing with such.

Resources