How to plot a ROC curve from TPR and FPR - r

I have a case where I only get TP, FP, FN and TN for every single data point (one example). In total, I have 24 examples (data points) with these 4 measures. I use 2 different methods and compute TP, FP, FN and TN for each example (data point). Now, I want to compare the performance of these 2 different methods by plotting a ROC curve. I have calculated TPR (y-axis) and FPR (x-axis) and plot them using ggplot2 (see image link) but I don't know how can I fit the curves on these data points so that they look like classical/traditional ROC curve plots. SO that I can also compute the auROC curve.
Can somebody guide me how to do it? Thank you.
plot using ggplot:
ggplot(data, aes(x=FPR, y=TPR)) + geom_point(aes(shape=Class, colour = Class), size=1.5) + scale_shape(solid = FALSE) + theme_update(plot.title=element_text(hjust=0.5)) + xlim(0,1) + xlab("False Positive Rate (FPR)") + ylab("True Positive Rate (TPR)")
Here is the dput of my data:
> dput(data)
structure(list(Class = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("Epi",
"GE"), class = "factor"), TP = c(94L, 127L, 58L, 76L, 5L, 6L,
34L, 47L, 14L, 20L, 113L, 136L, 32L, 36L, 78L, 102L, 51L, 58L,
49L, 50L, 111L, 120L, 174L, 184L, 151L, 172L, 189L, 226L, 36L,
40L, 252L, 271L, 2L, 4L, 7L, 42L, 41L, 82L, 0L, 15L, 45L, 53L,
11L, 16L, 24L, 35L, 3L, 10L, 28L, 34L), FP = c(46L, 389L, 3L,
254L, 3L, 7L, 13L, 57L, 7L, 88L, 55L, 220L, 21L, 87L, 23L, 245L,
11L, 190L, 20L, 77L, 45L, 168L, 86L, 391L, 34L, 238L, 88L, 367L,
56L, 193L, 119L, 455L, 3L, 27L, 5L, 30L, 67L, 247L, 0L, 30L,
4L, 65L, 7L, 77L, 55L, 176L, 5L, 33L, 15L, 66L), FN = c(33L,
0L, 18L, 0L, 1L, 0L, 13L, 0L, 6L, 0L, 23L, 0L, 4L, 0L, 24L, 0L,
7L, 0L, 1L, 0L, 9L, 0L, 10L, 0L, 21L, 0L, 37L, 0L, 4L, 0L, 19L,
0L, 5L, 3L, 35L, 0L, 41L, 0L, 15L, 0L, 8L, 0L, 6L, 1L, 14L, 3L,
7L, 0L, 6L, 0L), TN = c(488L, 179L, 373L, 125L, 10L, 6L, 75L,
32L, 119L, 38L, 247L, 83L, 97L, 37L, 400L, 179L, 295L, 132L,
107L, 51L, 200L, 109L, 441L, 140L, 331L, 157L, 419L, 177L, 180L,
45L, 567L, 237L, 35L, 11L, 88L, 91L, 222L, 90L, 0L, 29L, 116L,
56L, 105L, 36L, 217L, 99L, 55L, 28L, 82L, 32L), TPR = c(0.74,
1, 0.76, 1, 0.83, 1, 0.72, 1, 0.7, 1, 0.83, 1, 0.89, 1, 0.76,
1, 0.88, 1, 0.98, 1, 0.92, 1, 0.95, 1, 0.88, 1, 0.84, 1, 0.9,
1, 0.93, 1, 0.29, 0.57, 0.17, 1, 0.5, 1, 0, 1, 0.85, 1, 0.65,
0.94, 0.63, 0.92, 0.3, 1, 0.82, 1), FPR = c(0.09, 0.68, 0.01,
0.67, 0.23, 0.54, 0.15, 0.64, 0.06, 0.7, 0.18, 0.73, 0.18, 0.7,
0.05, 0.58, 0.04, 0.59, 0.16, 0.6, 0.18, 0.61, 0.16, 0.74, 0.09,
0.6, 0.17, 0.67, 0.24, 0.81, 0.17, 0.66, 0.08, 0.71, 0.05, 0.25,
0.23, 0.73, NA, 0.51, 0.03, 0.54, 0.06, 0.68, 0.2, 0.64, 0.08,
0.54, 0.15, 0.67)), .Names = c("Class", "TP", "FP", "FN", "TN",
"TPR", "FPR"), class = "data.frame", row.names = c(NA, -50L))
EDIT:
This is how the header of data looks like:
> head(data)
Class TP FP FN TN TPR FPR
1 Epi 94 46 33 488 0.74 0.09
2 GE 127 389 0 179 1.00 0.68
3 Epi 58 3 18 373 0.76 0.01
4 GE 76 254 0 125 1.00 0.67
5 Epi 5 3 1 10 0.83 0.23
6 GE 6 7 0 6 1.00 0.54
I will explain the first 2 rows, the same explantation applies to the rest of them. I used 2 different methods (named Epi and GE) to calculate number of TP, FP, FN and TN in my predictions about 1 example ( represented in plot by 1 data point). Then I calculate TPR and FPR from them. Similarly, the same 2 methods I applied on rest of the 23 examples and this entire dataframe gives me the value of TP, FP, FN and TN for each method in every example (24 datapoints - 1 data point representing one example and its TPR/FPR rate calculated by one method i.e. either GE or Epi).

Related

How to use Predict in rms package for a multiple values?

I used cox model for Predict function rms package for individual values they are returning the correct result where as when I give multiple values it gives me weired results?
library(data.table)
library(survival)
library(survminer)
library(rms)
dput(df)
structure(list(ID = c(1001L, 1002L, 1003L, 1004L, 1006L, 1014L,
1015L, 1016L, 1018L, 1022L, 1024L, 1032L, 1040L, 1042L, 1049L,
1056L, 1059L, 1060L, 1066L, 1084L, 1087L, 1090L, 1093L, 1096L,
1097L, 1098L, 1099L, 1200L, 1205L, 1216L, 1221L, 1222L, 1225L,
1226L, 1233L, 1239L), Time = c(9L, 8L, 69L, 104L, 104L, 100L,
24L, 85L, 100L, 99L, 67L, 58L, 7L, 94L, 93L, 90L, 91L, 90L, 89L,
72L, 84L, 84L, 11L, 82L, 39L, 46L, 82L, 82L, 9L, 34L, 75L, 76L,
52L, 20L, 29L, 70L), Event = c(1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L,
1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L), Risk1 = c(0.1,
0.03, 0.02, 0.05, 0.01, 0.04, 0.03, 0.06, 0.02, 0.03, 0, 0, 0.11,
0.01, 0.03, 0, 0.01, 0.01, 0.01, 0, 0, 0, 0.05, 0.01, 0, 0, 0,
0, 0.04, 0, 0.07, 0.01, 0.01, 0, 0, 0), Risk2 = c(88L, 49L, 60L,
46L, 50L, 60L, 38L, 74L, 39L, 65L, 80L, 35L, 54L, 40L, 54L, 55L,
60L, 38L, 64L, 74L, 71L, 57L, 55L, 49L, 42L, 30L, 63L, 46L, 47L,
58L, 34L, 72L, 50L, 60L, 73L, 51L), Risk3 = c(2L, 2L, 2L, 3L,
3L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 3L, 1L, 3L, NA, 2L, 3L, 2L, 2L,
2L, NA, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 2L
)), class = "data.frame", row.names = c(NA, -36L)
followed by
ddist <- datadist(df)
options(datadist='ddist')
cox_model <-cph(Surv(Time,Event==1) ~ Risk1 + Risk2 + Risk3, x = T, y = T, data = df, surv = T)
Predict(cox_model, Risk1=3.2, Risk2=1, Risk3=0.5)
but when I give multiple values as follows:
Predict(cox_model,
Risk1=c(5,3,2,1.5,1.5,2,3,2.5,4,2,5.5,6,3,3.5,4,5,4.5,3,2,6,3,5,4,1.8,3,3.5,1.5,2.5,3.5,5,6,4,1.5,5,4,2.5),
Risk2=c(1,1,1,1,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,1,1,0,1,1,0,1,1,0,0,0),
Risk3=c(0,0.07,0,0.03,0.01,0.02,0.01,0,0.05,0,0.04,0.03,0.01,0.01,0.01,0,0.11,0.03,0,0.05,0,0,0.02,0.04,0.01,0,0,0.01,0.03,0,0.01,0,0.06,0,0,0.1))
It gives me a ouput with 46566 rows where as I have only 36 rows to predict

correlation plots for consecutive study sites within a loop: how can i add site names as main headers?

edited to include dput(Nitrate_set) output:
structure(list(SITE.NO = structure(c(41L, 42L, 41L, 3L, 35L,
42L, 40L, 40L, 40L, 1L, 40L, 1L, 40L, 40L, 16L, 40L, 42L, 40L,
40L, 42L, 1L, 42L, 40L, 1L, 40L, 1L, 40L, 4L, 42L, 21L, 15L,
5L, 36L, 40L, 40L, 2L, 41L, 6L, 2L, 12L, 42L, 19L, 2L, 1L, 1L,
1L, 2L, 42L, 1L, 2L, 7L, 1L, 39L, 2L, 2L, 2L, 2L, 39L, 11L, 37L,
2L, 1L, 1L, 1L, 1L, 32L, 1L, 41L, 2L, 2L, 1L, 2L, 1L, 1L, 2L,
1L, 2L, 40L, 42L, 1L, 2L, 38L, 1L, 1L, 2L, 2L, 2L, 41L, 38L,
1L, 8L, 42L, 42L, 1L, 2L, 2L, 33L, 1L, 2L, 18L, 2L, 1L, 2L, 2L,
1L, 41L, 1L, 2L, 1L, 40L, 1L, 2L, 2L, 2L, 1L, 2L, 41L, 10L, 14L,
2L, 2L, 2L, 2L, 42L, 9L, 1L, 1L, 2L, 2L, 2L, 38L, 1L, 1L, 2L,
2L, 38L, 42L, 38L, 40L, 42L, 41L, 1L, 1L, 2L, 38L, 38L, 1L, 38L,
2L, 1L, 2L, 2L, 2L, 17L, 2L, 42L, 41L, 2L, 1L, 1L, 2L, 1L, 38L,
1L, 1L, 38L, 38L, 38L, 38L, 2L, 1L, 2L, 26L, 38L, 38L, 1L, 2L,
38L, 38L, 2L, 1L, 1L, 1L, 38L, 38L, 1L, 31L, 2L, 2L, 1L, 1L,
34L, 24L, 38L, 2L, 28L, 38L, 25L, 38L, 38L, 38L, 38L, 39L, 1L,
38L, 1L, 29L, 38L, 38L, 1L, 38L, 2L, 2L, 22L, 1L, 27L, 1L, 30L,
38L, 38L, 1L, 2L, 2L, 38L, 2L, 38L, 38L, 38L, 13L, 38L, 1L, 38L,
1L, 23L, 2L, 39L, 20L, 38L, 38L, 2L, 38L, 38L, 38L, 38L, 38L,
38L, 38L, 38L, 38L, 1L, 38L, 38L, 41L, 38L, 1L, 38L, 38L, 2L,
38L, 38L, 38L, 38L, 1L, 38L, 1L, 38L, 2L, 2L, 38L, 1L, 40L, 2L,
42L, 41L, 42L, 38L, 42L, 38L, 41L, 2L, 42L, 1L, 38L, 38L, 42L,
2L, 42L, 38L, 38L, 2L, 2L, 2L, 39L, 40L, 2L, 42L, 1L, 1L, 38L,
40L, 41L, 2L, 41L, 41L, 1L, 2L, 41L, 1L, 39L, 41L, 1L, 41L, 40L,
1L, 39L, 39L, 2L, 40L, 38L, 1L, 2L, 2L, 38L, 39L, 1L, 2L, 38L,
41L, 38L, 38L, 2L, 38L, 38L, 41L, 2L, 39L, 43L, 39L, 41L, 43L,
43L, 43L, 43L, 41L, 39L, 39L, 41L, 43L, 41L, 39L, 39L, 39L, 39L,
39L, 39L, 43L, 43L, 43L, 43L, 43L, 41L), .Label = c("1110056",
"1111019", "1120054", "1120055", "1120060", "1120061", "1120062",
"1120065", "1120066", "1120067", "1120068", "1120069", "1120070",
"1120071", "1120073", "1120074", "1120075", "1120076", "1120077",
"1120078", "1120079", "1120080", "1120081", "1120082", "1120083",
"1120084", "1120085", "1120086", "1120087", "1120088", "1120089",
"1120090", "1120091", "1120092", "1120094", "1120095", "1120096",
"113006A", "122013A", "125013A", "126001A", "1260122", "141010A"
), class = "factor"), SITE.NAME = structure(c(8L, 5L, 8L, 2L,
2L, 5L, 4L, 4L, 4L, 3L, 4L, 3L, 4L, 4L, 2L, 4L, 5L, 4L, 4L, 5L,
3L, 5L, 4L, 3L, 4L, 3L, 4L, 2L, 5L, 2L, 2L, 2L, 2L, 4L, 4L, 7L,
8L, 2L, 7L, 2L, 5L, 2L, 7L, 3L, 3L, 3L, 7L, 5L, 3L, 7L, 2L, 3L,
6L, 7L, 7L, 7L, 7L, 6L, 2L, 2L, 7L, 3L, 3L, 3L, 3L, 2L, 3L, 8L,
7L, 7L, 3L, 7L, 3L, 3L, 7L, 3L, 7L, 4L, 5L, 3L, 7L, 9L, 3L, 3L,
7L, 7L, 7L, 8L, 9L, 3L, 2L, 5L, 5L, 3L, 7L, 7L, 2L, 3L, 7L, 2L,
7L, 3L, 7L, 7L, 3L, 8L, 3L, 7L, 3L, 4L, 3L, 7L, 7L, 7L, 3L, 7L,
8L, 2L, 2L, 7L, 7L, 7L, 7L,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at Dumbleton Weir Headwater", "Plane Creek at Sucrogen Weir",
"Proserpine River at Glen Isla", "Russell River at East Russell",
"Sandy Creek at Homebush", "Tully River at Euramo"), class = "factor"),
Date = structure(c(64L, 62L, 48L, 63L, 42L, 8L, 54L, 75L,
75L, 48L, 12L, 73L, 3L, 37L, 40L, 17L, 69L, 69L, 47L, 4L,
27L, 4L, 48L, 64L, 74L, 79L, 74L, 79L, 54L, 49L, 40L, 80L,
61L, 62L, 64L, 53L, 3L, 80L, 53L, 4L, 81L, 45L, 53L, 53L,
50L, 53L, 50L, 31L, 50L, 50L, 81L, 53L, 17L, 53L, 50L, 70L,
46L, 43L, 4L, 6L, 70L, 53L, 13L, 65L, 13L, 2L, 56L, 37L,
25L, 53L, 65L, 68L, 56L, 46L, 2L, 70L, 13L, 12L, 81L, 40L,
6L, 24L, 16L, 16L, 46L, 68L, 2L, 80L, 52L, 68L, 81L, 81L,
14L, 46L, 30L, 60L, 30L, 70L, 56L, 45L, 61L, 16L, 65L, 56L,
16L, 81L, 55L, 5L, 32L, 10L, 13L, 13L, 46L, 72L, 32L, 49L,
14L, 4L, 8L, 42L, 35L, 1L, 41L, 37L, 81L, 63L, 52L, 76L,
1L, 32L, 53L, 40L, 55L, 52L, 58L, 53L, 10L, 53L, 20L, 48L,
80L, 19L, 49L, 13L, 56L, 53L, 19L, 50L, 21L, 46L, 35L, 21L,
19L, 45L, 16L, 64L, 81L, 19L, 32L, 25L, 52L, 72L, 38L, 49L,
49L, 26L, 38L, 38L, 38L, 32L, 80L, 16L, 56L, 46L, 50L, 1L,
32L, 41L, 41L, 32L, 58L, 58L, 41L, 56L, 13L, 23L, 68L, 55L,
49L, 32L, 15L, 5L, 55L, 2L, 40L, 65L, 65L, 53L, 58L, 25L,
13L, 5L, 37L, 61L, 11L, 35L, 65L, 60L, 11L, 1L, 52L, 45L,
58L, 52L, 6L, 56L, 49L, 68L, 13L, 68L, 35L, 49L, 55L, 49L,
45L, 30L, 55L, 19L, 8L, 67L, 22L, 70L, 5L, 52L, 45L, 34L,
49L, 45L, 32L, 80L, 16L, 13L, 70L, 49L, 67L, 16L, 19L, 44L,
67L, 42L, 21L, 21L, 80L, 1L, 45L, 45L, 59L, 4L, 59L, 29L,
29L, 21L, 45L, 71L, 45L, 45L, 80L, 4L, 40L, 40L, 8L, 4L,
15L, 81L, 18L, 18L, 15L, 20L, 54L, 81L, 12L, 76L, 57L, 18L,
12L, 81L, 20L, 80L, 80L, 15L, 81L, 81L, 31L, 20L, 8L, 28L,
18L, 20L, 18L, 20L, 80L, 4L, 47L, 69L, 18L, 18L, 62L, 18L,
20L, 10L, 4L, 10L, 4L, 9L, 10L, 12L, 18L, 28L, 9L, 8L, 18L,
18L, 9L, 12L, 8L, 9L, 4L, 28L, 4L, 8L, 8L, 8L, 8L, 10L, 8L,
66L, 39L, 8L, 20L, 77L, 36L, 36L, 36L, 20L, 4L, 74L, 12L,
51L, 20L, 4L, 78L, 78L, 81L, 81L, 4L, 7L, 7L, 7L, 7L, 33L,
12L), .Label = c("1/01/2019", "1/02/2019", "1/11/2018", "10/12/2018",
"11/02/2019", "11/03/2019", "11/04/2019", "11/12/2018", "12/12/2018",
"13/12/2018", "14/01/2019", "14/12/2018", "15/01/2019", "15/11/2018",
"15/12/2018", "16/01/2019", "16/11/2018", "16/12/2018", "17/01/2019",
"17/12/2018", "18/01/2019", "18/02/2019", "18/03/2019", "18/09/2018",
"19/01/2019", "19/02/2019", "19/11/2018", "19/12/2018", "2/01/2019",
"2/02/2019", "2/11/2018", "20/01/2019", "20/04/2019", "20/12/2018",
"21/01/2019", "21/04/2019", "22/11/2018", "24/01/2019", "24/04/2019",
"24/12/2018", "25/01/2019", "25/02/2019", "25/09/2018", "25/10/2018",
"25/12/2018", "26/01/2019", "26/09/2018", "26/11/2018", "26/12/2018",
"27/01/2019", "27/03/2019", "27/12/2018", "28/01/2019", "28/08/2018",
"28/12/2018", "29/01/2019", "29/11/2018", "29/12/2018", "3/01/2019",
"3/02/2019", "3/03/2019", "3/07/2018", "3/09/2018", "3/12/2018",
"30/01/2019", "30/11/2018", "30/12/2018", "31/01/2019", "31/07/2018",
"31/12/2018", "4/01/2019", "4/02/2019", "5/11/2018", "5/12/2018",
"6/12/2018", "7/01/2019", "7/03/2019", "7/12/2018", "8/10/2018",
"8/12/2018", "9/12/2018"), class = "factor"), Trios.nitrate..mg.L. = c(0.01,
0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.02, 0.02, 0.03, 0.03,
0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.04, 0.04, 0.04, 0.04,
0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.06, 0.06,
0.07, 0.07, 0.07, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.09,
0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11,
0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.12, 0.12, 0.12, 0.12,
0.12, 0.12, 0.12, 0.12, 0.12, 0.13, 0.13, 0.13, 0.13, 0.13,
0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13,
0.13, 0.13, 0.13, 0.13, 0.13, 0.14, 0.14, 0.14, 0.14, 0.14,
0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.14,
0.14, 0.14, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15,
0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.16, 0.16, 0.16,
0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.17,
0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.17, 0.18, 0.18, 0.18,
0.18, 0.18, 0.18, 0.18, 0.18, 0.18, 0.18, 0.18, 0.19, 0.19,
0.19, 0.19, 0.19, 0.19, 0.19, 0.19, 0.19, 0.19, 0.19, 0.19,
0.19, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
0.2, 0.2, 0.2, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21,
0.21, 0.21, 0.21, 0.21, 0.21, 0.22, 0.22, 0.22, 0.22, 0.22,
0.22, 0.22, 0.22, 0.22, 0.22, 0.22, 0.22, 0.22, 0.22, 0.22,
0.22, 0.22, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23,
0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23,
0.23, 0.23, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24,
0.24, 0.24, 0.24, 0.25, 0.25, 0.25, 0.26, 0.26, 0.26, 0.26,
0.26, 0.26, 0.26, 0.26, 0.26, 0.26, 0.26, 0.26, 0.26, 0.27,
0.27, 0.27, 0.28, 0.28, 0.3, 0.3, 0.3, 0.31, 0.31, 0.31,
0.31, 0.31, 0.32, 0.32, 0.33, 0.34, 0.34, 0.34, 0.35, 0.35,
0.36, 0.36, 0.37, 0.37, 0.37, 0.38, 0.38, 0.38, 0.38, 0.38,
0.39, 0.39, 0.4, 0.42, 0.42, 0.42, 0.43, 0.44, 0.48, 0.49,
0.49, 0.51, 0.51, 0.53, 0.56, 0.57, 0.58, 0.58, 0.58, 0.58,
0.58, 0.61, 0.64, 0.73, 0.76, 0.76, 0.81, 0.82, 0.85, 0.85,
0.85, 0.86, 0.88, 0.92, 0.94, 0.96, 1, 1.04, 1.04, 1.06,
1.14, 1.18, 1.34, 1.37, 1.45, 1.48, 1.48, 1.48, 1.54, 1.58,
1.73, 1.76, 1.82, 1.85, 1.95, 1.95, 1.96, 2.15, 2.18, 2.26,
2.3, 2.3, 2.3, 2.3, 2.69, 3.12), Chem.centre.Nox..mg.L. = c(5e-04,
0.001, 0.086, 0.048, 0.036, 0.015, 0.001, 0.088, 0.305, 0.012,
0.078, 0.023, 0.047, 0.002, 0.08, 0.004, 0.002, 0.003, 0.002,
0.029, 0.009, 0.045, 0.062, 0.006, 0.149, 0.087, 0.311, 0.008,
5e-04, 0.152, 0.03, 0.339, 0.103, 0.048, 0.003, 0.039, 0.159,
0.156, 0.043, 0.209, 0.091, 0.135, 0.039, 0.042, 0.041, 0.049,
0.045, 0.021, 0.045, 0.044, 0.235, 0.051, 0.03, 0.063, 0.046,
0.075, 0.058, 0.303, 0.227, 0.092, 0.094, 0.066, 0.068, 0.055,
0.073, 0.186, 0.079, 5e-04, 0.073, 0.086, 0.074, 0.097, 0.083,
0.062, 0.086, 0.084, 0.088, 0.098, 0.033, 0.093, 0.122, 0.104,
0.09, 0.093, 0.078, 0.095, 0.086, 0.178, 0.155, 0.098, 0.123,
0.134, 0.005, 0.065, 0.105, 0.109, 0.175, 0.098, 0.093, 0.081,
0.116, 0.116, 0.097, 0.098, 0.114, 0.159, 0.083, 0.126, 0.119,
0.092, 0.104, 0.116, 0.093, 0.114, 0.12, 0.118, 5e-04, 0.185,
0.265, 0.14, 0.168, 0.133, 0.116, 0.006, 0.057, 0.149, 0.086,
0.143, 0.137, 0.134, 0.164, 0.237, 0.114, 0.106, 0.123, 0.121,
0.086, 0.117, 0.184, 5e-04, 0.198, 0.148, 0.103, 0.159, 0.128,
0.134, 0.156, 0.134, 0.172, 0.082, 0.168, 0.176, 0.168, 0.153,
0.167, 0.001, 0.162, 0.171, 0.165, 0.152, 0.156, 0.17, 0.126,
0.124, 0.105, 0.188, 0.159, 0.17, 0.147, 0.174, 0.099, 0.176,
0.15, 0.141, 0.213, 0.166, 0.173, 0.181, 0.188, 0.192, 0.156,
0.062, 0.157, 0.167, 0.149, 0.234, 0.13, 0.172, 0.154, 0.194,
0.389, 0.171, 0.163, 0.181, 0.2, 0.156, 0.186, 0.17, 0.19,
0.196, 0.156, 0.218, 0.298, 0.218, 0.184, 0.206, 0.154, 0.193,
0.18, 0.192, 0.192, 0.145, 0.196, 0.158, 0.23, 0.172, 0.171,
0.154, 0.162, 0.209, 0.215, 0.179, 0.196, 0.183, 0.161, 0.208,
0.194, 0.208, 0.22, 0.178, 0.274, 0.184, 0.214, 0.222, 0.144,
0.169, 0.168, 0.183, 0.223, 0.184, 0.195, 0.181, 0.2, 0.202,
0.218, 0.191, 0.223, 0.057, 0.206, 0.237, 0.231, 0.244, 0.295,
0.217, 0.153, 0.214, 0.256, 0.17, 0.246, 0.25, 0.232, 0.247,
0.168, 0.247, 0.156, 0.214, 0.196, 0.183, 0.24, 0.205, 0.519,
0.197, 0.119, 0.306, 0.143, 0.257, 0.118, 0.269, 0.352, 0.256,
0.13, 0.307, 0.066, 0.272, 0.19, 0.261, 0.172, 0.222, 0.232,
0.236, 0.29, 0.276, 0.316, 0.217, 0.257, 0.206, 0.247, 0.28,
0.322, 0.304, 0.412, 0.36, 0.377, 0.421, 0.326, 0.33, 0.464,
0.331, 0.212, 0.456, 0.434, 0.486, 0.253, 0.48, 0.337, 0.549,
0.45, 0.611, 0.579, 0.594, 0.613, 0.672, 0.663, 0.389, 0.694,
0.718, 0.71, 0.692, 0.754, 0.816, 0.77, 0.863, 0.878, 0.388,
0.914, 0.42, 0.918, 1.06, 0.859, 1.58, 1.39, 0.922, 0.633,
1.22, 1.31, 0.399, 1.46, 1.71, 1.51, 1.58, 0.271, 0.44, 4.24,
3.65, 2.06, 2.61, 5e-04, 0.001, 0.065, 1.38, 2.91)), class = "data.frame", row.names = c(NA,
-361L))
>
The input file (Nitrate_set) includes 9 study sites. I have been able to produce a correlation plot between two variables of interest consecutively for each site within a loop, but am unable to add to appropriate site name as a header for each plot. Here's an example of the data:
SITE.NAME COR
1 Coochin Creek at Mawsons Road -0.1122249
2 Johnstone River at Coquette Point Gbr_Jri_Wq 0.3614868
3 Mulgrave River at Deeral 0.9338604
4 Pioneer River at Dumbleton Weir Headwater 0.7270477
5 Plane Creek at Sucrogen Weir 0.8337472
6 Proserpine River at Glen Isla 0.6695578
7 Russell River at East Russell 0.9879924
8 Sandy Creek at Homebush 0.9756037
9 Tully River at Euramo 0.9751152
I would like each correlation plot to display a header appropriate to it's site name. I'm not sure where to put that code within the loop.
This is the first time I am trying to produce plots within a loop and I'm a novice coder. I don't know what to try next..
#Creating function func to calculate correlation for single site
func <- function(Nitrate_set){ return(data.frame(COR = cor(Nitrate_set$Trios.nitrate..mg.L., Nitrate_set$Chem.centre.Nox..mg.L.))) }
#Calling func Function for each site name and storing the results in cor_result. cor_result will show correlation for each site as a list.
cor_result <- ddply(Nitrate_set, .(SITE.NAME), func)
cor_result
#Creating function to display correlation plot for every site
funcPlot <- function(Nitrate_set){
chart.Correlation(Nitrate_set[,c(4,5)], histogram=TRUE, pch=19)
}
#Calling the function to display the plots. This will return nine plots serially. At this point we need to title site name for each site.
ddply(Nitrate_set, .(SITE.NAME), funcPlot)
I expect each plot to be displayed with a header but am unable to work out how and where to put that section of code within the loop

ggplot2: Inconsistent color from alpha

I am making several plots that have different x-axis limits, and I want to highlight a region of interest by adding a grey box. Even though I use the same geom_rect() command with the same alpha value in ggplot2, I get results with very different grey colors. I have looked here and here but so far have not figured out how to make these boxes the same level of transparency. Below is a reproducible example (with fake data) and the figures that it produces. Notice the different color of the grey rectangles. I want the grey to be the same across plots.
Data<-structure(list(X = c(34L, 27L, 28L, 47L, 26L, 3L, 13L, 31L, 39L,
16L, 45L, 5L, 49L, 17L, 29L, 43L, 1L, 35L, 41L, 10L, 48L, 24L,
12L, 11L, 30L, 40L, 8L, 4L, 20L, 25L, 50L, 22L, 9L, 21L, 18L,
7L, 15L, 44L, 6L, 36L, 46L, 33L, 2L, 37L, 23L, 14L, 42L, 38L,
19L, 32L, 34L, 27L, 28L, 47L, 26L, 3L, 13L, 31L, 39L, 16L, 45L,
5L, 49L, 17L, 29L, 43L, 1L, 35L, 41L, 10L, 48L, 24L, 12L, 11L,
30L, 40L, 8L, 4L, 20L, 25L, 50L, 22L, 9L, 21L, 18L, 7L, 15L,
44L, 6L, 36L, 46L, 33L, 2L, 37L, 23L, 14L, 42L, 38L, 19L, 32L
), Y = c(130L, 146L, 58L, 110L, 117L, 135L, 133L, 108L, 97L,
61L, 71L, 64L, 103L, 142L, 125L, 104L, 100L, 147L, 111L, 78L,
56L, 145L, 62L, 69L, 70L, 116L, 137L, 79L, 150L, 94L, 91L, 81L,
65L, 118L, 129L, 83L, 98L, 84L, 85L, 148L, 93L, 73L, 59L, 87L,
134L, 88L, 136L, 90L, 140L, 55L, 89L, 115L, 123L, 51L, 132L,
126L, 66L, 80L, 60L, 120L, 109L, 76L, 74L, 57L, 149L, 121L, 138L,
128L, 114L, 127L, 68L, 107L, 67L, 112L, 144L, 119L, 53L, 52L,
54L, 96L, 131L, 106L, 113L, 72L, 95L, 63L, 92L, 86L, 75L, 105L,
82L, 101L, 139L, 143L, 122L, 77L, 99L, 141L, 124L, 102L), B = structure(c(2L,
2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L,
1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L,
2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L,
2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 1L, 1L), class = "factor", .Label = c("no", "yes"))), .Names = c("X",
"Y", "B"), row.names = c(NA, -100L), class = "data.frame")
Data2<-structure(list(variable = c(2.49676547444708, 0.67359598601097,
0.674751772966082, 0.0317590441796792, 0.485143583939748, 1.08231639527806,
0.0732344181040914, 1.62357048819912, 0.146833215667032, 0.823157103468943,
0.240761579418538, 1.37540376416553), DOY_mid_month = c(15, 46,
75, 106, 136, 167, 197, 228, 259, 289, 320, 350)), .Names = c("variable",
"DOY_mid_month"), row.names = c(NA, -12L), class = "data.frame")
test<-ggplot(data=Data) +
geom_rect(aes(xmin=5, xmax=30, ymin=1, ymax=40), alpha = 0.02) +
geom_point(aes(x = X, y = X, colour= B), data =Data, size=2) +
theme_bw()
test2 <-ggplot(data=Data2) +
geom_rect(aes(xmin=5, xmax=30, ymin=-Inf, ymax=Inf), alpha = 0.02) +
geom_point(aes(x = DOY_mid_month, y = variable), color="black", size=4) +
scale_x_continuous("Day of Year", limits = c(0, 366)) + # Use this to add back X-axis label for the bottom plot in panel
scale_y_continuous(expression(paste("Variable", sep=""))) +
theme_bw()
Plot result from first example:
Plot result from second example:
You are currently drawing one rectangle for each row of the dataset. The more rectangles you overlap, the darker they get, which is why the longer dataset has a darker rectangle. Use annotate instead of geom_rect to draw a single rectangle.
annotate(geom = "rect", xmin=5, xmax=30, ymin=-Inf, ymax=Inf, alpha = 0.2)
If you want to stick with geom_rect you can give a one row data.frame to that layer so that each rectangle is only drawn one time. Here I use a fake dataset, although you could put your rectangle limits in the data.frame, as well.
geom_rect(data = data.frame(fake = 1),
aes(xmin = 5, xmax= 30, ymin = -Inf, ymax = Inf), alpha = 0.2)

R - Lattice xyplot - How do you add error bars to groups and summary lines?

I'm posting this question because the very similar question here has not been answered until now.
I have been asked to plot the mean +/- SEM of my whole cohort of patients over the xyplot() that depicts the values of all patients. The data used represents intraoperative cardiovascular findings from patients undergoing surgery.
This is my data.frame called df
dput(df)
structure(list(Name = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L), .Label = c("DE", "JS", "KG", "MK", "TG", "WT"), class = "factor"),
Time = structure(c(1L, 2L, 3L, 4L, 5L, 7L, 8L, 1L, 2L, 3L,
4L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 7L, 8L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 2L, 3L, 4L, 5L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L), .Label = c("T1", "T2", "T3", "T4", "T5", "T6", "T7",
"T8"), class = "factor"), Dobut = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L), .Label = c("No", "Yes"
), class = "factor"), DobutDose = c(NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
4L, 6L, 8L, 8L, 8L, 8L, 8L, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, 5L, 5L, NA), CI = c(1.4, 2.3, 1.3, 1.8, 2.1,
2, 2.1, 2.1, 2.3, 1.9, 1.6, 2, 2.4, 2.7, 2.6, 2.7, 2.6, 2.3,
2.4, 2.6, 0.9, 2.5, 2.1, 1.6, 1.5, 1.8, 2, 2, 1.9, 2.1, 2.3,
2, 2.4, 2.3, 2.6, 2.4, 2, 2.2, 1.6, 2.1, 2.5, 2.8), SvO2 = c(57L,
65L, 47L, 45L, 51L, 60L, 56L, 70L, 85L, 75L, 79L, 82L, 73L,
77L, 78L, 73L, 71L, 73L, 80L, 74L, 41L, 66L, 51L, 51L, 49L,
54L, 68L, 48L, 80L, 70L, 71L, 69L, 74L, 79L, 77L, 77L, 75L,
74L, 70L, 79L, 80L, 79L), SVRI = c(4000L, 1983L, 4000L, 2444L,
1981L, 2120L, 2514L, 2971L, 2157L, 3747L, 4300L, 3200L, 2867L,
1778L, 1169L, 1215L, 1262L, 1461L, 1600L, 1692L, 4978L, 1760L,
2019L, 2650L, 2827L, 2356L, 1800L, 2840L, 2063L, 2248L, 1948L,
2160L, 1733L, 2296L, 2677L, 2100L, 2640L, 2655L, 3950L, 2210L,
2848L, 2543L), MAP = c(80L, 65L, 86L, 74L, 67L, 65L, 74L,
90L, 70L, 90L, 96L, 94L, 100L, 82L, 60L, 61L, 62L, 62L, 69L,
71L, 70L, 71L, 77L, 73L, 75L, 77L, 61L, 85L, 65L, 74L, 70L,
67L, 69L, 74L, 92L, 71L, 88L, 93L, 89L, 79L, 97L, 97L), CVP = c(10L,
8L, 21L, 19L, 15L, 12L, 8L, 12L, 8L, 11L, 10L, 14L, 14L,
22L, 22L, 20L, 21L, 20L, 21L, 16L, 14L, 16L, 24L, 20L, 22L,
24L, 16L, 14L, 16L, 15L, 14L, 13L, 17L, 8L, 5L, 8L, 22L,
20L, 20L, 21L, 8L, 8L), PAP = c(23L, 22L, 36L, 36L, 34L,
32L, 22L, 33L, 28L, 36L, 36L, 40L, 37L, 37L, 40L, 35L, 35L,
34L, 38L, 36L, 45L, 43L, 55L, 49L, 52L, 54L, 43L, 47L, 27L,
25L, 23L, 22L, 28L, 21L, 20L, 25L, 33L, 33L, 38L, 35L, 33L,
29L), PCWP = c(15L, 11L, 28L, 26L, 23L, 21L, 11L, 26L, NA,
NA, 25L, 25L, NA, 27L, NA, NA, NA, NA, NA, NA, 30L, NA, NA,
NA, NA, NA, NA, NA, 19L, NA, NA, NA, NA, NA, 16L, NA, NA,
NA, NA, NA, NA, NA)), .Names = c("Name", "Time", "Dobut",
"DobutDose", "CI", "SvO2", "SVRI", "MAP", "CVP", "PAP", "PCWP"
), class = "data.frame", row.names = c(NA, -42L))
Now the first xyplot I made for the variable CI looks like this
require(lattice)
xyplot(CI~Time, groups=Name, data=df, ty=c("l", "p"),
+ ,xlab="Measurement Time Point",
ylab=expression("CI"~(l/min/m^"2")), main="Cardiac Index")
Now I was able to add the mean (black line) of the whole cohort, by doing the following
xyplot(CI~Time, groups=Name, data=df, ty=c("l", "p"),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.linejoin(x, y, horizontal = FALSE,..., col="black", lty=1, lwd=4)
}
,xlab="Measurement Time Point",
ylab=expression("CI"~(l/min/m^"2")), main="Cardiac Index")
Now I'd like to add +/- SE to the mean as a line above/below the mean, but nowhere can I find how to do this.
What I can do is using the latticeExtra package is add the loess line +/- SE, as below, but that's not the correct mathematical function I'm looking for. I've left the mean line in there to illustrate the difference between the two.
require(latticeExtra)
xyplot(CI~Time, groups=Name, data=df, ty=c("l", "p"),
+ panel = function(x, y, ...) {
+ panel.xyplot(x, y, ...)
+ panel.linejoin(x, y, horizontal = FALSE,..., col="black", lty=1, lwd=4)
+ panel.smoother(x,y,se=TRUE, col.se="grey")
+ }
+ ,xlab="Measurement Time Point",
ylab=expression("CI"~(l/min/m^"2")), main="Cardiac Index")
I have performed an extensive search through SO and the internet, but I haven't been able to find the right function to do this.
Help is very much appreciated! Thanks.
You could create your own panel function to plot a +/- SD region. For example
#new panel function
panel.se <- function(x, y, col.se=plot.line$col, alpha.se=.25, ...) {
plot.line <- trellis.par.get("plot.line")
xs <- if(is.factor(x)) {
factor(c(levels(x) , rev(levels(x))), levels=levels(x))
} else {
xx <- sort(unique(x))
c(xx, rev(xx))
}
means <- tapply(y,x, mean, na.rm=T)
vars <- tapply(y,x, var, na.rm=T)
Ns <- tapply(!is.na(y),x, sum)
ses <- sqrt(vars/Ns)
panel.polygon(xs, c(means+ses, rev(means-ses)), col=col.se, alpha=alpha.se)
}
and then you can use it like
#include new panel function
xyplot(CI~Time, groups=Name, data=df, ty=c("l", "p"),
panel = function(x, y, ...) {
panel.se(x,y, col.se="grey")
panel.xyplot(x, y, ...)
panel.linejoin(x, y, horizontal = FALSE,..., col="black", lty=1, lwd=4)
}
,xlab="Measurement Time Point",
ylab=expression("CI"~(l/min/m^"2")), main="Cardiac Index")
which results in

Is `format` more secure than `$` when extracting hours from a POSIXlt vector?

Starting R with a bare-bone
l#np350v5c:~$ R --vanilla
> search()
[1] ".GlobalEnv" "package:stats" "package:graphics"
[4] "package:grDevices" "package:utils" "package:datasets"
[7] "package:methods" "Autoloads" "package:base"
.. this is a dump of data (emergency accesses hours in a northern Italy hospital) which gave a strange (to me) behaviour:
times <- structure(list(sec = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0), min = c(5L, 43L, 2L, 47L, 15L, 18L, 46L, 50L, 58L,
26L, 14L, 54L, 28L, 11L, 32L, 17L, 51L, 40L, 17L, 47L, 21L, 57L,
59L, 34L, 45L, 15L, 10L, 25L, 27L, 31L, 5L, 34L, 5L, 36L, 16L,
2L, 20L, 0L, 24L, 1L, 54L, 59L, 28L, 24L, 24L, 19L, 26L, 1L,
48L, 0L, 10L, 18L, 43L, 38L, 24L, 21L, 37L, 36L, 54L, 11L, 27L,
29L, 34L, 32L, 33L, 43L, 40L, 53L, 56L, 48L, 47L, 54L, 11L, 37L,
14L, 46L, 30L, 54L, 0L, 38L, 27L, 57L, 21L, 31L, 21L, 37L, 17L,
41L, 21L, 14L, 33L, 33L, 31L, 6L, 30L, 48L, 49L, 26L, 9L, 0L,
19L, 45L, 5L, 9L, 29L, 15L, 34L, 48L, 20L, 25L, 1L, 49L, 48L,
46L, 47L, 18L, 48L, 35L, 56L, 24L, 41L, 13L, 37L, 53L, 57L, 11L,
9L, 43L, 30L, 11L, 55L, 56L, 12L, 35L, 14L, 48L, 22L, 44L, 25L,
51L, 51L, 27L, 58L, 23L, 17L, 42L, 21L, 54L, 59L, 40L, 37L, 43L,
15L, 12L, 22L, 15L, 55L, 7L, 21L, 59L, 34L, 38L, 15L, 8L, 57L,
49L, 6L, 1L, 51L, 46L, 49L, 20L, 46L, 56L, 32L, 36L, 56L, 47L,
58L, 23L, 14L, 56L, 4L, 44L, 25L, 44L, 22L, 21L, 36L, 35L, 58L,
27L, 22L, 44L, 16L, 5L, 34L, 46L, 52L, 18L, 0L, 32L, 49L, 3L,
16L, 53L, 57L, 58L, 35L, 21L, 32L, 57L, 7L, 20L, 29L, 26L, 48L,
53L, 9L, 59L, 58L, 30L, 57L, 34L, 6L, 29L, 57L, 10L, 25L, 15L,
26L, 29L, 20L, 24L, 36L, 54L, 46L, 24L, 14L, 10L, 48L, 22L, 17L,
39L, 59L, 33L, 12L, 0L, 29L, 36L, 31L, 57L, 38L, 10L, 29L, 42L,
36L, 16L, 2L, 21L, 35L, 4L, 16L, 33L, 35L, 14L, 37L, 25L, 51L,
12L, 45L, 15L, 7L, 33L, 42L, 28L, 19L, 40L, 5L, 39L, 13L, 23L,
47L, 31L, 7L, 12L, 8L, 7L, 24L, 37L, 51L, 49L, 11L, 0L, 23L,
30L, 37L, 48L, 26L, 42L, 33L, 8L, 17L, 4L, 51L, 26L, 48L, 17L,
43L, 35L, 35L, 27L, 27L, 47L, 17L, 24L, 43L, 55L, 20L, 54L, 38L,
58L, 2L, 37L, 26L, 3L, 25L, 18L, 0L, 58L, 57L, 12L, 10L, 51L,
37L, 23L, 57L, 14L, 7L, 22L, 50L, 14L, 24L, 27L, 42L, 53L, 6L,
21L, 56L, 17L, 4L, 6L, 30L, 47L, 42L, 20L, 17L, 0L, 35L, 59L,
46L, 50L, 16L, 15L, 42L, 26L, 36L, 8L, 35L, 2L, 59L, 12L, 14L,
58L, 3L, 0L, 37L, 36L, 23L, 29L, 45L, 44L, 32L, 25L, 1L, 50L,
17L, 56L, 58L, 53L, 35L, 17L, 14L, 38L, 27L, 27L, 8L, 14L, 7L,
24L, 13L, 42L, 21L, 12L, 38L, 24L, 30L, 27L, 55L, 23L, 31L, 43L,
22L, 47L, 50L, 27L, 56L, 22L, 54L, 23L, 46L, 17L, 30L, 41L, 54L,
41L, 51L, 44L, 34L, 42L, 3L, 57L, 9L, 51L, 54L, 58L, 53L, 58L,
4L, 12L, 12L, 35L, 55L, 5L, 4L, 15L, 56L, 14L, 48L, 57L, 13L,
19L, 25L, 24L, 24L, 2L, 54L), hour = c(-3, -4, -3, -2, -4, -1,
-5, -4, -5, -5, -5, -4, -3, -2, -4, -2, -2, -4, -4, -1, -2, -5,
-5, -2, -2, -2, -5, -1, -1, -4, -3, -4, -4, -3, -4, -3, -1, -2,
-2, -1, -2, -5, -5, -3, -2, -2, -3, -3, -4, -1, -4, -3, -4, -2,
-5, -2, -4, -5, -4, -2, -5, -1, -5, -3, -2, -1, -3, -5, -1, -3,
-5, -1, -5, -1, -3, -1, -2, -5, -3, -1, -5, -1, -1, -3, -5, -1,
-2, -4, -4, -5, -3, -5, -4, -1, -5, -2, -5, -3, -5, -5, -2, -1,
-5, -3, -5, -3, -2, -4, -3, -1, -1, -2, -3, -1, -4, -3, -4, -5,
-1, -5, -3, -3, -1, -3, -3, -4, -4, -2, -5, -5, -1, -3, -5, -2,
-3, -2, -1, -5, -3, -5, -1, -1, -1, -3, -3, -5, -1, -2, -4, -2,
-4, -1, -4, -5, -1, -5, -1, -1, -4, -2, -5, -5, -3, -1, -5, -3,
-4, -5, -4, -5, -3, -5, -5, -5, -2, -5, -3, -5, -3, -4, -4, -5,
-5, -1, -4, -4, -1, -3, -1, -3, -3, -4, -2, -2, -4, -3, -1, -4,
-5, -3, -1, -3, -4, -3, -5, -1, -3, -5, -4, -5, -2, -4, -1, -3,
-5, -2, -5, -3, -4, -2, -5, -4, -1, -5, -3, -5, -1, -2, -2, -4,
-3, -4, -2, -4, -3, -4, -2, -5, -1, -1, -2, -1, -3, -5, -1, -1,
-2, -4, -4, -5, -3, -3, -3, -4, -4, -4, -4, -3, -4, -2, -5, -4,
-1, -4, -5, -4, -3, -3, -5, -2, -3, -1, -4, -1, -5, -2, -1, -1,
-4, -3, -2, -5, -4, -3, -4, -1, -3, -4, -5, -3, -2, -4, -1, -4,
-4, -2, -5, -3, -5, -1, -3, -4, -2, -1, -2, -3, -5, -3, -1, -1,
-3, -4, -4, -2, -2, -1, -2, -1, -4, -2, -5, -2, -1, -3, -5, -1,
-5, -3, -3, -5, -2, -1, -1, -4, -5, -5, -4, -1, -3, -5, -2, -4,
-1, -2, -4, -5, -5, -1, -5, -5, -4, -2, -5, -2, -3, -2, -2, -2,
-3, -2, -4, -4, -5, -1, -2, -5, -3, -1, -1, -4, -1, -5, -3, -5,
-4, -2, -4, -3, -4, -4, -3, -2, -2, -5, -2, -1, -1, -1, -3, -5,
-4, -5, -1, -1, -3, -2, -4, -2, -2, -1, -2, -4, -3, -5, -2, -1,
-4, -4, -1, -4, -2, -3, -2, -1, -5, -5, -4, -2, -1, -5, -3, -3,
-4, -5, -3, -4, -1, -3, -2, -2, -2, -4, -1, -2, -2, -2, -5, -1,
-4, -2, -4, -2, -5, -4, -2, -3, -2, -1, -1, -1, -3, -2, -5, -3,
-5, -2, -1), mday = c(24L, 30L, 13L, 17L, 11L, 17L, 1L, 26L,
21L, 1L, 9L, 6L, 7L, 17L, 17L, 4L, 24L, 23L, 31L, 2L, 22L, 19L,
12L, 17L, 26L, 13L, 12L, 26L, 14L, 20L, 22L, 14L, 26L, 29L, 7L,
16L, 19L, 10L, 19L, 17L, 15L, 22L, 4L, 22L, 6L, 22L, 6L, 24L,
18L, 11L, 13L, 26L, 5L, 2L, 1L, 12L, 15L, 21L, 22L, 24L, 25L,
18L, 4L, 18L, 28L, 4L, 21L, 25L, 18L, 4L, 8L, 10L, 21L, 11L,
11L, 20L, 23L, 14L, 16L, 2L, 31L, 3L, 21L, 3L, 1L, 13L, 26L,
20L, 17L, 4L, 3L, 13L, 10L, 23L, 16L, 1L, 28L, 27L, 16L, 29L,
6L, 15L, 6L, 14L, 4L, 17L, 15L, 4L, 19L, 26L, 20L, 22L, 24L,
1L, 16L, 18L, 12L, 21L, 26L, 11L, 30L, 19L, 26L, 4L, 3L, 2L,
26L, 30L, 14L, 16L, 21L, 20L, 29L, 26L, 17L, 23L, 8L, 19L, 23L,
14L, 14L, 5L, 28L, 6L, 15L, 13L, 8L, 6L, 1L, 2L, 3L, 5L, 16L,
17L, 3L, 23L, 20L, 27L, 28L, 1L, 31L, 26L, 14L, 30L, 22L, 9L,
31L, 5L, 19L, 9L, 27L, 26L, 24L, 12L, 27L, 20L, 9L, 4L, 9L, 4L,
18L, 9L, 13L, 10L, 23L, 27L, 11L, 21L, 6L, 6L, 6L, 9L, 23L, 14L,
27L, 23L, 17L, 19L, 29L, 16L, 18L, 4L, 5L, 29L, 14L, 16L, 19L,
25L, 14L, 16L, 27L, 12L, 11L, 26L, 2L, 17L, 1L, 20L, 2L, 3L,
5L, 7L, 27L, 27L, 17L, 6L, 4L, 11L, 5L, 15L, 13L, 19L, 1L, 29L,
18L, 29L, 17L, 23L, 31L, 26L, 19L, 17L, 14L, 21L, 17L, 13L, 5L,
13L, 4L, 27L, 13L, 18L, 4L, 24L, 23L, 21L, 25L, 25L, 2L, 24L,
25L, 28L, 6L, 10L, 15L, 9L, 7L, 8L, 9L, 22L, 17L, 11L, 15L, 24L,
14L, 23L, 18L, 28L, 3L, 20L, 25L, 5L, 17L, 21L, 24L, 21L, 24L,
3L, 31L, 21L, 18L, 27L, 30L, 25L, 13L, 8L, 21L, 16L, 22L, 24L,
3L, 16L, 4L, 22L, 15L, 30L, 2L, 16L, 28L, 24L, 26L, 20L, 9L,
3L, 3L, 4L, 11L, 5L, 30L, 19L, 24L, 3L, 24L, 5L, 14L, 4L, 23L,
18L, 7L, 16L, 24L, 3L, 27L, 4L, 30L, 22L, 28L, 17L, 25L, 3L,
19L, 18L, 26L, 8L, 24L, 18L, 17L, 6L, 17L, 25L, 6L, 23L, 14L,
4L, 5L, 15L, 5L, 4L, 19L, 4L, 7L, 24L, 28L, 23L, 28L, 9L, 7L,
27L, 26L, 25L, 4L, 19L, 24L, 18L, 18L, 7L, 16L, 11L, 10L, 21L,
6L, 30L, 15L, 1L, 16L, 16L, 21L, 17L, 8L, 19L, 1L, 23L, 10L,
18L, 2L, 8L, 20L, 28L, 25L, 28L, 25L, 23L, 5L, 4L, 31L, 2L, 21L,
30L, 1L, 4L, 18L, 8L, 25L, 1L, 25L, 2L, 5L, 20L, 2L, 17L, 5L,
5L, 30L, 30L, 17L, 5L, 18L, 21L, 24L, 20L, 26L, 31L, 15L, 30L,
16L, 6L, 18L, 28L, 7L, 25L, 24L, 7L, 23L, 9L, 8L, 25L, 11L, 20L,
19L, 24L, 5L, 5L, 26L, 26L, 7L, 29L, 22L), mon = c(10L, 4L, 7L,
7L, 4L, 10L, 11L, 5L, 5L, 5L, 1L, 5L, 10L, 9L, 1L, 6L, 7L, 7L,
0L, 5L, 7L, 10L, 6L, 4L, 4L, 6L, 11L, 10L, 8L, 3L, 6L, 1L, 5L,
6L, 11L, 8L, 4L, 5L, 2L, 8L, 0L, 4L, 1L, 1L, 11L, 0L, 2L, 11L,
6L, 1L, 4L, 6L, 9L, 6L, 4L, 10L, 0L, 9L, 5L, 1L, 8L, 1L, 6L,
6L, 4L, 3L, 8L, 11L, 7L, 4L, 11L, 9L, 5L, 4L, 6L, 0L, 7L, 0L,
1L, 10L, 11L, 4L, 7L, 7L, 9L, 9L, 9L, 10L, 3L, 1L, 9L, 3L, 5L,
11L, 6L, 10L, 10L, 0L, 11L, 3L, 9L, 10L, 6L, 8L, 5L, 7L, 7L,
8L, 1L, 9L, 2L, 11L, 1L, 6L, 7L, 10L, 2L, 8L, 8L, 8L, 8L, 4L,
1L, 0L, 0L, 5L, 6L, 6L, 3L, 5L, 7L, 7L, 11L, 6L, 1L, 8L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, 10L, 3L, 10L, 5L, 10L, 7L, 9L, 9L, 2L, 10L, 0L, 9L, 4L, 7L,
7L, 11L, 1L, 11L, 1L, 1L, 4L, 2L, 3L, 3L, 5L, 10L, 0L, 7L, 9L,
7L, 10L, 10L, 4L, 2L, 0L, 0L, 1L, 7L, 8L, 6L, 9L, 9L, 11L, 4L,
6L, 8L, 9L, 0L, 8L, 6L, 4L, 6L, 7L, 4L, 0L, 0L, 9L, 1L, 4L, 0L,
1L, 8L, 1L, 3L, 7L), year = c(112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,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, 34L, 52L, 340L,
21L, 65L, 358L, 199L, 41L, 133L, 207L, 278L, 183L, 121L, 316L,
14L, 294L, 173L, 54L, 268L, 48L, 185L, 199L, 148L, 94L, 264L,
359L, 230L, 124L, 342L, 283L, 172L, 131L, 192L, 19L, 235L, 13L,
46L, 306L, 365L, 123L, 233L, 215L, 274L, 286L, 299L, 324L, 107L,
34L, 276L, 103L, 161L, 357L, 197L, 305L, 332L, 26L, 350L, 119L,
279L, 319L, 187L, 257L, 155L, 229L, 227L, 247L, 49L, 299L, 79L,
356L, 54L, 182L, 228L, 322L, 71L, 264L, 269L, 254L, 273L, 139L,
56L, 3L, 2L, 153L, 207L, 211L, 104L, 167L, 233L, 232L, 363L,
207L, 47L, 266L, 312L, 292L, 82L, 318L, 318L, 4L, 118L, 279L,
288L, 225L, 220L, 36L, 274L, 61L, 62L, 4L, 228L, 16L, 215L, 327L,
232L, 178L, 240L, 152L, 243L, 360L, 134L, 334L, 234L, 343L, 212L,
339L, 323L, 190L, 86L, 207L, 23L, 224L, 331L, 79L, 282L, 124L,
39L, 63L, 230L, 252L, 103L, 314L, 327L, 270L, 10L, 294L, 96L,
340L, 187L, 343L, 174L, 73L, 270L, 82L, 351L, 353L, 59L, 259L,
48L, 185L, 248L, 149L, 134L, 106L, 49L, 55L, 257L, 320L, 239L,
102L, 254L, 177L, 122L, 47L, 213L, 232L, 183L, 62L, 186L, 280L,
208L, 361L, 260L, 187L, 308L, 70L, 35L, 227L, 194L, 323L, 152L,
149L, 48L, 28L, 47L, 22L, 365L, 85L, 200L, 290L, 348L, 355L,
321L, 347L, 217L, 256L, 124L, 208L, 286L, 138L, 247L, 297L, 296L,
325L, 329L, 115L, 214L, 297L, 145L, 271L, 65L, 314L, 319L, 129L,
97L, 38L, 282L, 234L, 290L, 101L, 166L, 23L, 257L, 296L, 230L,
271L, 154L, 232L, 268L, 248L, 321L, 51L, 236L, 80L, 297L, 246L,
90L, 172L, 17L, 331L, 181L, 206L, 72L, 312L, 51L, 259L, 234L,
23L, 33L, 106L, 277L, 112L, 196L, 150L, 306L, 15L, 118L, 175L,
146L, 324L, 282L, 215L, 123L, 94L, 10L, 95L, 120L, 49L, 297L,
154L, 114L, 95L, 257L, 338L, 327L, 138L, 341L, 15L, 236L, 33L,
26L, 124L, 89L, 81L, 27L, 16L, 237L, 123L, 139L, 322L, 269L,
98L, 267L, 352L, 260L, 5L, 16L, 206L, 187L, 53L, 13L, 94L, 125L,
74L, 278L, 34L, 200L, 124L, 97L, 54L, 27L, 22L, 362L, 39L, 127L,
117L, 238L, 329L, 63L, 49L, 23L, 17L, 169L, 127L, 259L, 315L,
222L, 325L, 249L, 273L, 45L, 244L, 350L, 259L, 325L, 229L, 342L,
139L, 244L, 53L, 314L, 108L, 306L, 159L, 324L, 240L, 298L, 301L,
84L, 327L, 4L, 277L, 151L, 214L, 233L, 364L, 31L, 338L, 48L,
38L, 145L, 60L, 115L, 92L, 156L, 324L, 1L, 229L, 278L, 217L,
334L, 334L, 137L, 64L, 17L, 20L, 54L, 232L, 269L, 212L, 288L,
303L, 350L, 126L, 199L, 271L, 280L, 24L, 267L, 188L, 143L, 190L,
220L, 145L, 10L, 19L, 292L, 54L, 125L, 4L, 56L, 269L, 37L, 119L,
234L), isdst = c(0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L,
1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L,
0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L,
0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L,
0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L,
1L, 1L, 0L, 1L, 0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L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L,
0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 1L,
0L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L,
1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L,
1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 1L)), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXlt", "POSIXt"))
Then, trying to extract hours in different ways
df <- data.frame(times,
with.dollar = times$hour,
with.format = as.numeric(format(times, "%H"))
)
head(df)
and my results are
times with.dollar with.format
1 2012-11-23 21:05:00 -3 21
2 2012-05-29 20:43:00 -4 20
3 2012-08-12 21:02:00 -3 21
4 2012-08-16 22:47:00 -2 22
5 2012-05-10 20:15:00 -4 20
6 2012-11-16 23:18:00 -1 23
Another test (not in a data.frame... simple vectors)
> any(times$hour == as.numeric(format(times, "%H")))
[1] FALSE
With times$hour it seems to be counting hours starting from the next days in some cases (all of the cases here reported).
Could you reproduce that? any idea why?
Looking at ?POSIXlt this could be a bug because not all hours are within 0:23 range.
If so, for the moment it would be safer to use format rather $ for POSIXlt vector
> R.version
_
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 0.3
year 2014
month 03
day 06
svn rev 65126
language R
version.string R version 3.0.3 (2014-03-06)
nickname Warm Puppy

Resources