Is there any way to speed up this loop? - r

I am pretty new to programming and am looking for help to speed up this process. At the current rate the loop will take approximately 24-30 hours.
library(readxl)
## Load data##
A02_pre <- read_excel("C:/Users/Gebruiker/Desktop/Nieuwe map/Mappen participanten/Pre/A02/A02_vivo13_wk2_4mei_90uur.xlsx",
col_types = c("text", "text", "text",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"text", "text", "text", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "text", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "text", "numeric",
"numeric", "numeric", "numeric",
"text", "text"))
A02_pre_hr <- read_excel("C:/Users/Gebruiker/Desktop/Nieuwe map/Mappen participanten/Pre/A02/A02 - 17817.xlsx", )
View(A02_pre_hr)
### Convert string to date time ##
A02_pre$`ns1:Time` = as.POSIXct(A02_pre$`ns1:Time`,
format="%Y-%m-%dT%H:%M:%OSZ",tz ="GMT")
A02_pre_hr$start = as.POSIXct(substr(A02_pre_hr$start,1,nchar(A02_pre_hr$start)-4),
format="%Y-%m-%d %H:%M:%S",tz ="GMT")
## Test dates ##
A02_pre$`ns1:Time`[1] < A02_pre_hr$start[1]
measurementTime <- A02_pre$`ns1:Time`
heartRate <- A02_pre$`ns1:Value4`
**### Run for loop starting here
toCheck = 1:length(measurementTime)
maxj = 0
for(i in 1:(nrow(A02_pre_hr)-1)){
activityStartTime = A02_pre_hr$start[i]
activityEndTime= A02_pre_hr$start[i+1]
heartRateSum = 0
heartRateCount = 0
## Loop over heart rate measurements & assign average to activity
for(j in toCheck[toCheck>maxj]){
if(measurementTime[j]>=activityStartTime & measurementTime[j]<= activityEndTime){
heartRateCount = heartRateCount+1
heartRateSum = heartRateSum + heartRate[j]
}else if(heartRateCount>0){
break;
}
}
averageHeartRate = NA
if(heartRateCount>0){
averageHeartRate = heartRateSum / heartRateCount
}
A02_pre_hr$averageHeartRate[i] = averageHeartRate
print(i)
}**
### Summary ####
by(A02_pre_hr$averageHeartRate, A02_pre_hr$class, summary)
dput(A02_pre)
structure(list(`ns1:Value4` = c(78, 77, 82, 87, 92, 97, 99, 100,
101, 102, 103, 104, 105, 106, 105, 104, 103, 102, 101, 100, 99,
98, 97, 96, 97, 98, 99, 101, 102, 104, 105, 106, 105, 104, 103,
102, 101, 100, 99, 98, 97, 96, 97, 98, 99, 100, 101, 99, 100,
101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 94, 98,
100, 101, 99, 97, 96, 95, 94, 93, 94, 93, 92, 91, 90, 89, 90,
89, 88, 85, 83, 82, 81, 80, 79, 78, 77, 75, 74, 72, 71, 70, 69,
68, 67, 66, 65, 64, 63, 62, 63, 62, 65, 68, 71, 73, 75, 77, 79,
81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 90, 89, 88, 87, 86,
85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 75, 74, 73, 72,
71, 70, 69, 68, 67, 66, 65, 67, 68, 69, 68, 67, 71, 74, 77, 79,
81, 83, 85, 87, 88, 90, 89, 88, 89, 88, 87, 86, 85, 84, 83, 85,
87, 89, 90, 92, 91, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
101, 102, 103, 107, 111, 114, 117, 117, 116, 115, 116, 117, 118,
119, 120, 119, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108,
107, 106, 105, 104, 103, 102, 100, 99, 98, 97, 96, 95, 94, 93,
92, 90, 88, 89, 90, 91, 93, 94, 95, 96, 95, 94, 93, 92, 91, 90,
89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 98, 97, 96, 97, 98,
99, 100, 99, 98, 97, 98, 97, 96, 95, 94, 93, 92, 91, 90, 91,
90, 89, 87, 85, 83, 81, 80, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 95, 98, 102, 105, 107, 110, 112, 114, 116, 115, 114,
113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101,
100, 99, 98, 97, 96, 95, 94, 95, 94, 95, 96, 95, 94, 93, 94,
93, 92, 91, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100, 103, 105,
106, 108, 107, 106, 105, 104, 105, 106, 105, 104, 105, 106, 107,
106, 105, 104, 103, 104, 103, 104, 100, 99, 98, 97, 96, 95, 94,
93, 92, 93, 94, 95, 97, 98, 99, 100, 99, 100, 101, 100, 99, 100,
99, 98, 99, 100, 99, 100, 99, 97, 94, 91, 89, 90, 89, 88, 87,
85, 84, 85, 86, 87, 86, 85, 83, 81, 80, 79, 78, 77, 76, 75, 74,
72, 71, 70, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 83,
84, 85, 86, 85, 84, 85, 86, 87, 88, 87, 88, 89, 90, 91, 92, 91,
89, 88, 87, 88, 89, 90, 95, 96, 95, 94, 93, 92, 91, 90, 89, 88,
87, 86, 85, 84, 85, 86, 87, 86, 84, 85, 86, 87, 86, 87, 86, 85,
84, 83, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75), `ns1:Time` = structure(c(1525439315,
1525439321, 1525439325, 1525439326, 1525439327, 1525439328, 1525439329,
1525439330, 1525439332, 1525439333, 1525439335, 1525439337, 1525439339,
1525439346, 1525439355, 1525439400, 1525439401, 1525439402, 1525439403,
1525439405, 1525439406, 1525439407, 1525439409, 1525439410, 1525439413,
1525439414, 1525439415, 1525439417, 1525439418, 1525439419, 1525439421,
1525439425, 1525439429, 1525439430, 1525439432, 1525439433, 1525439434,
1525439436, 1525439437, 1525439438, 1525439440, 1525439441, 1525439443,
1525439444, 1525439445, 1525439447, 1525439448, 1525439451, 1525439452,
1525439455, 1525439457, 1525439458, 1525439460, 1525439461, 1525439462,
1525439463, 1525439464, 1525439466, 1525439467, 1525439469, 1525439471,
1525439473, 1525439475, 1525439476, 1525439477, 1525439478, 1525439479,
1525439480, 1525439481, 1525439483, 1525439484, 1525439486, 1525439488,
1525439489, 1525439490, 1525439491, 1525439493, 1525439494, 1525439495,
1525439496, 1525439497, 1525439499, 1525439500, 1525439502, 1525439504,
1525439506, 1525439508, 1525439510, 1525439511, 1525439514, 1525439515,
1525439516, 1525439517, 1525439519, 1525439526, 1525439531, 1525439536,
1525439537, 1525439539, 1525439540, 1525439541, 1525439544, 1525439563,
1525439577, 1525439587, 1525439588, 1525439589, 1525439590, 1525439591,
1525439592, 1525439593, 1525439594, 1525439595, 1525439596, 1525439597,
1525439598, 1525439599, 1525439600, 1525439601, 1525439602, 1525439604,
1525439606, 1525439607, 1525439608, 1525439610, 1525439611, 1525439613,
1525439614, 1525439616, 1525439618, 1525439620, 1525439621, 1525439623,
1525439626, 1525439628, 1525439630, 1525439633, 1525439636, 1525439638,
1525439640, 1525439641, 1525439644, 1525439647, 1525439651, 1525439656,
1525439660, 1525439666, 1525439673, 1525439680, 1525439690, 1525439703,
1525439704, 1525439705, 1525439717, 1525439728, 1525439732, 1525439733,
1525439734, 1525439735, 1525439736, 1525439737, 1525439738, 1525439739,
1525439740, 1525439741, 1525439742, 1525439743, 1525439749, 1525439751,
1525439754, 1525439756, 1525439758, 1525439760, 1525439762, 1525439765,
1525439766, 1525439767, 1525439768, 1525439769, 1525439770, 1525439771,
1525439773, 1525439774, 1525439775, 1525439776, 1525439777, 1525439780,
1525439782, 1525439784, 1525439785, 1525439786, 1525439788, 1525439791,
1525439797, 1525439811, 1525439812, 1525439813, 1525439814, 1525439815,
1525439816, 1525439819, 1525439820, 1525439821, 1525439822, 1525439823,
1525439824, 1525439828, 1525439829, 1525439830, 1525439831, 1525439832,
1525439833, 1525439834, 1525439835, 1525439836, 1525439837, 1525439838,
1525439839, 1525439840, 1525439841, 1525439842, 1525439843, 1525439844,
1525439846, 1525439847, 1525439849, 1525439850, 1525439852, 1525439853,
1525439855, 1525439857, 1525439858, 1525439859, 1525439860, 1525439863,
1525439864, 1525439865, 1525439866, 1525439870, 1525439872, 1525439880,
1525439885, 1525439887, 1525439888, 1525439889, 1525439891, 1525439892,
1525439894, 1525439895, 1525439896, 1525439898, 1525439899, 1525439901,
1525439904, 1525439907, 1525439915, 1525439925, 1525439964, 1525439965,
1525439966, 1525439967, 1525439970, 1525439975, 1525439987, 1525440021,
1525440052, 1525440053, 1525440055, 1525440066, 1525440098, 1525440100,
1525440101, 1525440102, 1525440104, 1525440105, 1525440106, 1525440108,
1525440109, 1525440111, 1525440113, 1525440114, 1525440115, 1525440116,
1525440117, 1525440118, 1525440120, 1525440122, 1525440124, 1525440125,
1525440130, 1525440137, 1525440141, 1525440145, 1525440171, 1525440186,
1525440189, 1525440194, 1525440202, 1525440203, 1525440204, 1525440205,
1525440206, 1525440207, 1525440208, 1525440209, 1525440210, 1525440211,
1525440213, 1525440214, 1525440216, 1525440218, 1525440220, 1525440222,
1525440225, 1525440228, 1525440231, 1525440235, 1525440238, 1525440241,
1525440246, 1525440251, 1525440256, 1525440267, 1525440268, 1525440269,
1525440276, 1525440303, 1525440314, 1525440316, 1525440321, 1525440330,
1525440331, 1525440332, 1525440334, 1525440351, 1525440364, 1525440408,
1525440409, 1525440411, 1525440412, 1525440416, 1525440422, 1525440424,
1525440427, 1525440430, 1525440436, 1525440454, 1525440457, 1525440458,
1525440459, 1525440460, 1525440461, 1525440462, 1525440468, 1525440473,
1525440479, 1525440503, 1525440508, 1525440509, 1525440513, 1525440530,
1525440550, 1525440551, 1525440552, 1525440556, 1525440557, 1525440558,
1525440563, 1525440572, 1525440576, 1525440579, 1525440607, 1525440609,
1525440614, 1525440615, 1525440616, 1525440618, 1525440620, 1525440621,
1525440623, 1525440627, 1525440628, 1525440629, 1525440630, 1525440635,
1525440637, 1525440640, 1525440642, 1525440643, 1525440649, 1525440655,
1525440668, 1525440676, 1525440692, 1525440714, 1525440725, 1525440729,
1525440731, 1525440732, 1525440733, 1525440734, 1525440735, 1525440736,
1525440737, 1525440744, 1525440746, 1525440747, 1525440748, 1525440749,
1525440750, 1525440752, 1525440756, 1525440757, 1525440767, 1525440768,
1525440769, 1525440770, 1525440771, 1525440772, 1525440773, 1525440775,
1525440778, 1525440780, 1525440783, 1525440785, 1525440786, 1525440787,
1525440789, 1525440790, 1525440792, 1525440795, 1525440799, 1525440803,
1525440808, 1525440810, 1525440813, 1525440818, 1525440820, 1525440821,
1525440822, 1525440826, 1525440831, 1525440838, 1525440839, 1525440848,
1525440850, 1525440852, 1525440853, 1525440855, 1525440857, 1525440858,
1525440862, 1525440867, 1525440871, 1525440907, 1525440908, 1525440909,
1525440910, 1525440911, 1525440914, 1525440916, 1525440917, 1525440918,
1525440919, 1525440920, 1525440938, 1525440952, 1525440962, 1525440970,
1525440975, 1525441002, 1525441014, 1525441015, 1525441017, 1525441019,
1525441020, 1525441021, 1525441024, 1525441028, 1525441033, 1525441034,
1525441036, 1525441048, 1525441054, 1525441056, 1525441057, 1525441078,
1525441079, 1525441081, 1525441083, 1525441085, 1525441087, 1525441089,
1525441091, 1525441093, 1525441096, 1525441098, 1525441100, 1525441103,
1525441106), tzone = "GMT", class = c("POSIXct", "POSIXt"))), row.names = c(NA,
-500L), class = c("tbl_df", "tbl", "data.frame"))
dput(A02_pre_hr)
structure(list(results_id = c(17817, 17817, 17817, 17817, 17817,
17817, 17817, 17817, 17817, 17817, 17817, 17817, 17817, 17817,
17817, 17817, 17817, 17817, 17817, 17817, 17817, 17817, 17817,
17817, 17817, 17817, 17817, 17817, 17817, 17817, 17817, 17817,
17817, 17817, 17817, 17817, 17817, 17817, 17817, 17817, 17817,
17817, 17817, 17817, 17817), start = structure(c(1525439377,
1525439400, 1525439460, 1525439520, 1525439580, 1525439640, 1525439700,
1525439760, 1525439781, 1525439783, 1525439820, 1525439880, 1525439940,
1525439954, 1525439957, 1525440000, 1525440051, 1525440053, 1525440058,
1525440060, 1525440120, 1525440180, 1525440240, 1525440300, 1525440360,
1525440420, 1525440480, 1525440540, 1525440600, 1525440660, 1525440720,
1525440780, 1525440840, 1525440900, 1525440960, 1525441020, 1525441080,
1525441140, 1525441200, 1525441260, 1525441320, 1525441380, 1525441440,
1525441500, 1525441560), tzone = "GMT", class = c("POSIXct",
"POSIXt")), duration = c(22.37, 60, 60, 60, 60, 60, 60, 21.04,
2.65, 36.32, 60, 60, 14.58, 3.07, 42.35, 51.38, 2.46, 4.78, 1.38,
60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
60, 60, 60, 60, 60, 60, 60, 60, 60, 60), class = c("standing",
"standing", "standing", "standing", "standing", "standing", "standing",
"standing", "walking", "standing", "standing", "standing", "standing",
"sitting", "standing", "standing", "walking", "standing", "lying",
"lying", "lying", "lying", "lying", "lying", "lying", "lying",
"lying", "lying", "lying", "lying", "lying", "lying", "lying",
"lying", "lying", "lying", "lying", "lying", "lying", "lying",
"lying", "lying", "lying", "lying", "lying"), steps = c(0, 0,
0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0), mi = c(2, 12, 1, 11, 2, 102, 329, 285, 351, 193, 190, 225,
148, 361, 180, 226, 230, 379, 349, 212, 30, 125, 225, 36, 1,
1, 1, 2, 1, 1, 1, 1, 1, 10, 40, 8, 8, 9, 8, 9, 9, 10, 9, 7, 2
), aee = c(16, 21, 15, 20, 16, 64, 173, 151, 313, 107, 106, 123,
86, 129, 101, 123, 246, 197, 448, 272, 38, 160, 289, 46, 1, 1,
1, 2, 1, 1, 1, 1, 1, 12, 51, 10, 10, 11, 10, 11, 11, 12, 11,
9, 2), tee = c(91, 96, 90, 96, 91, 144, 265, 242, 421, 192, 191,
210, 169, 216, 186, 210, 346, 292, 571, 375, 116, 251, 394, 124,
74, 74, 74, 76, 74, 74, 74, 74, 74, 87, 130, 84, 84, 86, 84,
86, 86, 87, 86, 83, 76), met = c(1.145, 1.208, 1.139, 1.201,
1.145, 1.767, 3.18, 2.906, 6.847, 2.334, 2.315, 2.533, 2.054,
2.424, 2.253, 2.539, 5.12, 3.491, 7.275, 4.802, 1.516, 3.231,
5.036, 1.624, 0.992, 0.992, 0.992, 1.01, 0.992, 0.992, 0.992,
0.992, 0.992, 1.155, 1.697, 1.119, 1.119, 1.137, 1.119, 1.137,
1.137, 1.155, 1.137, 1.101, 1.01), counts = c(14, 138, 0, 256,
0, 2059, 7922, 2162, 394, 2952, 2886, 3888, 782, 62, 2163, 3041,
128, 560, 169, 3506, 432, 2024, 3825, 844, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 392, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0), averageHeartRate = c(104,
100.236842105263, 88.6904761904762, 64.9, 81.1944444444444, 70,
80.4347826086957, 90.1333333333333, 97, 108.285714285714, 103.775,
93.2941176470588, NA, NA, 97.7142857142857, 100, 98.5, 97.5,
NA, 89.5, 83, 105.833333333333, 99.5, 94.5555555555556, 91.8333333333333,
100.4, 104.8, 104.7, 97, 99, 87.4642857142857, 76.4090909090909,
87.5, 91.3076923076923, 88, 85.6923076923077, 82.0714285714286,
91.2, 86.6428571428571, 90.6363636363636, 105.142857142857, 95.5,
94.1, 102.5, 93.8333333333333)), row.names = c(NA, -45L), class = c("tbl_df",
"tbl", "data.frame"))

I'm trying to get an average heart rate out of every activity. The
heart rate has been measured with a sports watch and the activities
(sitting, lying, walking etc) have been measured with an accelerometer
(which in turn estimates what kind of activity was being done).
You could use a data.table non-qui join with by = .EACHI. That should be quite fast.
library(data.table)
setDT(A02_pre_hr)
setDT(A02_pre)
A02_pre_hr[, start := as.POSIXct(start)]
A02_pre_hr[, end := start + duration]
A02_pre[, time := as.POSIXct(`ns1:Time`)]
A02_pre_hr[, averageHeartRate1 := A02_pre[A02_pre_hr, mean(`ns1:Value4`, na.rm = TRUE),
on = c("time >= start", "time <= end"), by = .EACHI]$V1]
# results_id start duration class steps mi aee tee met counts averageHeartRate end averageHeartRate1
# 1: 17817 2018-05-04 13:09:37 22.37 standing 0 2 16 91 1.145 14 104.00000 2018-05-04 13:09:59 NaN
# 2: 17817 2018-05-04 13:10:00 60.00 standing 0 12 21 96 1.208 138 100.23684 2018-05-04 13:11:00 100.23684
# 3: 17817 2018-05-04 13:11:00 60.00 standing 0 1 15 90 1.139 0 88.69048 2018-05-04 13:12:00 88.69048
# 4: 17817 2018-05-04 13:12:00 60.00 standing 0 11 20 96 1.201 256 64.90000 2018-05-04 13:13:00 64.90000
# 5: 17817 2018-05-04 13:13:00 60.00 standing 0 2 16 91 1.145 0 81.19444 2018-05-04 13:14:00 81.19444
# 6: 17817 2018-05-04 13:14:00 60.00 standing 0 102 64 144 1.767 2059 70.00000 2018-05-04 13:15:00 70.00000
# 7: 17817 2018-05-04 13:15:00 60.00 standing 0 329 173 265 3.180 7922 80.43478 2018-05-04 13:16:00 80.43478
# ....
The first value doesn't match because of the subseconds in the duration.

Related

How to identify parameters for SARIMA model in R

Part 2 Boston
plot(boston, ylab=" Boston crime data", xlab= "Time")
#Time series seem to have homogeneous variance upon visual inspection
#Q2
#Trend looks linear in the plot, so for trend differencing operator take d=1
newboston= as.numeric(unlist(boston))
xdiff = diff(newboston)
plot(xdiff)
#Q3
#ADF
library(tseries)
adf.test(xdiff)
#From the result, alternative hypothesis is stationary so null hypothesis is rejected
#KPSS test
install.packages('fpp3', dependencies = TRUE)
library ( fpp3 )
unitroot_kpss(xdiff)
#the p-value is >0.05, so fail to reject null hypothesis for KPSS
#Q4
library(astsa)
acf2(xdiff, max.lag = 50)
model1 = sarima(xdiff, p, 1, q)
So this is what I have tried so far. I am quite new to R and so do be kind if my workings make little sense. For context, Boston is the data I imported from an excel, that is simply a column of x axis data.
Firstly, I am trying to do Q4, but I am not sure how I would go about to find p and q.
Second, I am unsure whether what I did in Q2 to detrend my data is correct in the first place.
Here is the output of dput(boston)
dput(boston)
structure(list(x = c(41, 39, 50, 40, 43, 38, 44, 35, 39, 35,
29, 49, 50, 59, 63, 32, 39, 47, 53, 60, 57, 52, 70, 90, 74, 62,
55, 84, 94, 70, 108, 139, 120, 97, 126, 149, 158, 124, 140, 109,
114, 77, 120, 133, 110, 92, 97, 78, 99, 107, 112, 90, 98, 125,
155, 190, 236, 189, 174, 178, 136, 161, 171, 149, 184, 155, 276,
224, 213, 279, 268, 287, 238, 213, 257, 293, 212, 246, 353, 339,
308, 247, 257, 322, 298, 273, 312, 249, 286, 279, 309, 401, 309,
328, 353, 354, 327, 324, 285, 243, 241, 287, 355, 460, 364, 487,
452, 391, 500, 451, 375, 372, 302, 316, 398, 394, 431, 431),
y = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-118L))

Save multiple plots at once

I have a large database to test normality, and I am making plots through a loop
The example piece of df
structure(list(paciente = c(6278, 6447, 6462, 6213, 6358, 6295,
6523, 6174, 6343, 6270, 6483, 6307, 6467, 6219, 6446, 6274, 6001,
6002, 6003, 6004, 6005, 6006, 6014, 6016, 6019, 6024, 6026, 6028,
6030, 6031, 6043, 6044, 6048, 6051, 6053, 6054, 6059, 6066, 6074,
6080, 6085, 6088, 6092, 6094, 6096, 6098, 6100, 6102, 6103, 6104,
6105, 6109, 6110, 6118, 6124, 6126, 6127, 6129, 6132, 6133, 6136,
6137, 6139, 6140, 6142, 6143, 6144, 6148, 6190, 6287, 6285, 6194,
6167, 6206, 6271, 6555, 6416, 6513, 6374, 6400, 6325, 6371, 6440,
6185, 6451, 6487, 6419, 6529, 6311, 6551, 6378, 6181, 6210, 6557,
6203, 6175, 6150, 6470, 6204, 6166, 6355, 6477, 6534, 6286, 6561,
6336, 6232, 6354, 6531, 6297, 6296, 6156, 6516, 6324, 6290, 6256,
6176, 6410, 6277, 6254, 6173, 6151, 6499, 6248, 6546, 6280, 6152,
6461, 6283, 6362, 6255, 6428, 6272, 6266, 6550, 6344, 6247, 6372,
6454, 6237, 6539, 6387, 6215, 6251, 6330, 6180, 6515, 6238, 6201,
6549, 6409, 6313, 6212, 6221, 6480, 6522, 6223, 6249, 6331, 6305,
6352, 6484, 6357, 6281, 6257, 6432, 6545, 6345, 6379, 6236, 6498,
6479, 6363, 6346, 6284, 6300, 6288, 6507, 6200, 6413, 6423, 6350,
6326, 6229, 6368, 6386, 6434, 6509, 6244, 6293, 6530, 6427, 6453,
6508, 6337, 6250, 6327, 6466, 6339, 6341, 6373, 6430, 6494, 6165,
6188, 6207, 6463, 6431, 6268, 6230, 6351, 6485, 6383, 6364, 6239,
6160, 6235, 6162, 6528, 6007, 6009, 6011, 6012, 6015, 6017, 6020,
6022, 6023, 6029, 6032, 6036, 6038, 6039, 6040, 6041, 6045, 6049,
6050, 6052, 6056, 6060, 6061, 6062, 6063, 6064, 6065, 6069, 6072,
6081, 6082, 6083, 6086, 6087, 6089, 6090, 6091, 6093, 6097, 6099,
6101, 6108, 6112, 6116, 6119, 6120, 6122, 6123, 6125, 6134, 6135,
6138, 6141, 6145, 6147, 6198, 6233, 6217, 6258, 6161, 6242, 6218,
6323, 6178, 6279, 6476, 6514, 6262, 6321, 6460, 6308, 6224, 6205,
6208, 6302, 6195, 6153, 6532, 6500, 6492, 6240, 6457, 6273, 6422,
6367, 6318, 6490, 6228, 6496, 6227, 6243, 6414, 6415, 6197, 6267,
6306, 6177, 6155, 6260, 6459, 6264, 6154, 6170, 6263, 6304, 6259,
6171, 6202, 6292, 6269, 6481, 6322, 6493, 6526, 6519, 6486, 6226,
6169, 6450, 6445, 6261, 6438, 6252, 6468, 6220, 6505, 6299, 6193,
6149, 6317, 6222, 6189, 6394, 6231, 6553, 6241, 6164, 6234, 6158,
6216, 6375, 6168, 6452, 6265, 6537, 6369, 6294, 6488, 6214, 6291,
6191, 6183, 6211, 6276, 6437, 6199, 6472, 6335, 6245, 6489, 6448,
6504, 6506, 6347, 6253, 6163, 6316, 6502, 6246, 6179, 6473, 6282,
6510, 6482, 6192, 6196, 6275, 6527, 6186, 6439, 6475, 6533, 6289,
6503, 6298, 6436, 6225, 6376), sexo_s1 = structure(c(1, 0, 0,
1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0,
1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1,
1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0,
0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0,
1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0,
1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0,
1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1,
1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1,
0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1,
1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0,
0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1,
0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0,
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1,
0, 1, 0, 1, 1), label = "Sexo", format.spss = "F2.0", labels = c(Hombre = 0,
Mujer = 1), class = c("haven_labelled", "vctrs_vctr", "double"
)), edad_s1 = c(66, 67, 62, 66, 73, 61, 68, 62, 65, 65, 60, 60,
62, 65, 71, 70, 72, 70, 69, 73, 70, 61, 64, 56, 68, 74, 73, 67,
68, 65, 67, 67, 70, 63, 61, 66, 72, 61, 61, 63, 65, 68, 67, 66,
68, 63, 74, 71, 57, 62, 70, 74, 61, 61, 59, 62, 65, 67, 59, 65,
68, 65, 65, 60, 69, 71, 65, 55, 63, 63, 61, 64, 71, 63, 60, 72,
62, 64, 70, 71, 71, 64, 64, 64, 71, 69, 55, 65, 64, 72, 64, 71,
69, 68, 75, 70, 72, 67, 60, 71, 60, 57, 65, 64, 66, 56, 57, 72,
64, 74, 67, 67, 60, 61, 66, 69, 72, 75, 60, 68, 66, 64, 62, 68,
68, 66, 67, 63, 69, 66, 65, 61, 56, 67, 63, 62, 68, 63, 64, 58,
72, 70, 70, 63, 63, 75, 65, 66, 64, 65, 71, 64, 67, 70, 61, 72,
71, 74, 60, 65, 75, 60, 58, 65, 58, 71, 69, 64, 75, 60, 64, 64,
66, 67, 66, 60, 64, 60, 57, 61, 63, 63, 70, 73, 71, 63, 66, 67,
61, 73, 68, 66, 63, 60, 64, 69, 66, 69, 60, 62, 62, 63, 63, 73,
58, 69, 55, 63, 60, 64, 66, 60, 63, 63, 61, 66, 60, 65, 59, 62,
72, 67, 68, 68, 61, 69, 70, 72, 60, 70, 61, 70, 65, 69, 72, 74,
58, 63, 63, 74, 66, 65, 66, 61, 66, 60, 63, 66, 72, 69, 70, 63,
66, 60, 67, 62, 57, 71, 63, 57, 58, 66, 67, 65, 60, 62, 61, 68,
70, 57, 62, 68, 67, 65, 63, 67, 65, 63, 62, 70, 61, 59, 64, 72,
67, 59, 67, 66, 64, 69, 70, 68, 74, 60, 63, 69, 68, 61, 61, 61,
61, 63, 66, 68, 68, 72, 71, 62, 69, 68, 70, 69, 62, 63, 62, 69,
73, 58, 71, 71, 69, 62, 66, 69, 65, 69, 59, 58, 72, 62, 67, 62,
66, 72, 56, 70, 70, 71, 59, 70, 61, 62, 69, 63, 68, 60, 55, 60,
61, 63, 67, 68, 66, 67, 64, 71, 65, 69, 61, 63, 73, 62, 72, 70,
63, 56, 62, 59, 68, 67, 68, 72, 58, 63, 62, 65, 70, 71, 67, 59,
61, 69, 66, 71, 65, 68, 60, 68, 69, 63, 66, 72, 74, 62, 63, 74,
63, 66, 60, 65, 58, 73, 73, 71, 58, 68, 61), peso1_v00 = c(71.3,
106, 76.8, 69.9, 85.1, 83, 102.7, 110.3, 80, 74.6, 95.9, 99,
103.2, 65, 81.2, 90.3, 82.4, 78, 66.7, 97.3, 85.3, 79.9, 73.2,
109.6, 71.1, 91.5, 60, 68.2, 70.8, 76.8, 96, 75.4, 63.9, 118.7,
76.3, 120.1, 80.6, 92.4, 82.6, 80.1, 79.6, 82, 86.2, 90.4, 57.8,
66.3, 63.7, 109.7, 103.4, 85, 77.6, 96.8, 92.5, 76.9, 99.5, 78.6,
95.5, 89.3, 90.4, 70.1, 96.2, 75, 72.5, 67.1, 82.7, 82.8, 104.4,
113.2, 78, 65.5, 123.5, 98.9, 78.7, 90.7, 106.6, 72, 84.2, 91,
71.6, 93.4, 105.4, 122, 87.6, 86.4, 68, 85.5, 91.3, 66, 85.8,
103.4, 98.7, 94.8, 83, 83.8, 92.8, 77.7, 66, 92.6, 98.3, 85.4,
81.2, 107, 132.5, 108.2, 112.4, 102, 88.9, 93.1, 74.8, 90.6,
74.4, 90, 101.8, 94.5, 86.5, 95.8, 84, 95.5, 76.7, 78.4, 72.6,
76.2, 97.9, 85.5, 129, 88.9, 92.5, 85.4, 94.2, 102.1, 80.5, 80.5,
105.7, 75.6, 102.5, 70.5, 105.5, 76.3, 101, 105.2, 83.5, 93.7,
90.9, 107.5, 98, 77.5, 103.1, 91.3, 72.1, 103.7, 91.6, 81.6,
92.4, 86.5, 75, 77.9, 102.5, 98, 82.1, 86.5, 77.5, 81.9, 112,
91.2, 97.4, 86.5, 70, 82, 76.7, 87.8, 104.1, 71.1, 84.4, 93.5,
76.8, 91.5, 65.3, 94.5, 88.3, 86.8, 65.2, 88.2, 66.5, 74, 84.1,
85, 101.2, 85.3, 68.5, 91.5, 89, 81.8, 85, 86, 111.4, 98.8, 90,
84.2, 62.7, 95, 85.8, 115.4, 76.2, 93.8, 107, 89.8, 101.5, 88,
88.2, 103.8, 78.2, 101, 80.5, 69.4, 85.6, 79.5, 110.2, 84.8,
99.8, 110.9, 69.7, 93.3, 66.7, 97.5, 82.4, 73.7, 80.2, 81.1,
73, 101.6, 93.6, 76, 103.2, 77.5, 88.8, 65.7, 117, 82.5, 76.2,
74.2, 91.9, 98.5, 106.5, 78.2, 85.1, 100.7, 79.2, 67.1, 70, 94.4,
91.5, 91.6, 87.1, 91.8, 95.5, 125.9, 110.8, 95.3, 102.9, 116.4,
91.1, 87.9, 78.6, 72, 108.2, 82.7, 117.2, 88.7, 110.1, 78.2,
83.1, 83, 88.2, 107.5, 90.7, 73.1, 98.8, 100.1, 88.9, 107, 100.7,
90, 82.2, 87.3, 80.2, 82.5, 107.9, 92.5, 89, 79.1, 99.5, 110.8,
72.7, 107.7, 127.6, 92.9, 66.8, 91.6, 97, 94.5, 99, 94.9, 77,
97.2, 90.7, 75, 114.6, 78.4, 85.6, 76.8, 88, 80.8, 98, 78.9,
82.5, 73.7, 79, 119.8, 86.6, 78.7, 65.4, 74.5, 82.1, 90.9, 81.5,
89.9, 90, 95.9, 77.3, 109, 71.9, 93, 57.9, 88.3, 93.4, 99.8,
95, 75.8, 88.2, 78.4, 83.1, 85, 87.7, 88.8, 92.2, 78.8, 93.2,
80.2, 76.8, 115.5, 93.4, 86.5, 70.3, 98.2, 91, 80.2, 88.4, 83,
68, 72.8, 80.9, 102.5, 90.3, 83.7, 70.1, 115.6, 62, 86.7, 92.6,
97.8, 75.1, 88.2, 110.9, 83, 101, 92.5, 94.2, 72.5, 70.5, 94.6,
87.5, 75.2, 85.3, 69.8, 80.4, 70, 92.5, 88.5, 81.7, 105, 106.2,
91.3, 110.2, 84.7, 95.8, 96.6, 90.5, 69.5, 98, 71, 137.5, 101.1,
73.5, 64.8, 101.5, 85.1, 80.2), cintura1_v00 = c(105, 124, 104,
100.5, 114, 100.5, 120.5, 132, 109, 101.5, 113, 123, 114, 95,
102, 115, 117, 105.5, 89, 109, 104, 108.5, 102.5, 122.5, 95.4,
119, 94, 96, 98.3, 100, 119.2, 102.8, 96, 136.2, 109.5, 132,
103, 113, 98.5, 106.8, 117.5, 102.3, 102, 116, 94, 94.3, 93.2,
127, 119, 96.5, 105.5, 113.5, 105.2, 112.8, 116.5, 102, 126,
114.5, 114, 103, 108, 107, 104, 101, 110, 110, 125, 128, 106,
97, 127.5, 118, 112, 104, 126.5, 107, 107, 109.5, 104, 107, 123,
128.5, 123, 109.5, 99, 102.5, 109, 97, 108, 120, 113.5, 123,
114.5, 105, 107, 106, 97, 115, 110.5, 109, 104.5, 129, 139, 120,
121, 119, 108, 116.5, 104, 111.5, 100, 102, 117, 111, 116.5,
124, 117, 112, 96, 104, 92, 110, 112.5, 110, 140, 119.5, 116,
104, 114, 114, 116, 106.5, 116, 108, 114.5, 101.5, 116, 100,
116, 116.5, 108.5, 113, 119, 116, 118, 105, 122, 121.5, 92.5,
124.5, 115.5, 110, 116, 106, 100, 106.5, 126.5, 123, 104, 98,
94, 115, 121.5, 107.5, 111.5, 102.5, 101, 106.5, 103, 101, 120.5,
117, 104.5, 116, 103, 112, 96, 118.5, 108.5, 107, 102.5, 106,
103, 105.5, 97.5, 103, 116.5, 114.5, 94, 112, 113.5, 110, 104,
113, 124, 112, 114.5, 113.4, 90, 114, 106, 123, 106.5, 117, 116.5,
107.5, 115, 103, 103, 118, 98, 103.5, 112.5, 95, 106, 103, 114,
113, 122, 126, 102.5, 117, 85, 115, 100.2, 106, 107.5, 110, 102.7,
126.3, 111.6, 103, 125, 107.7, 112, 91.5, 127.5, 117.7, 101,
104.5, 117, 121.5, 130.7, 105.2, 117.2, 116.2, 109, 97, 98, 115,
116, 107.5, 122, 116.7, 116.8, 131.8, 118.5, 115.5, 123.2, 122.6,
115, 115, 113.2, 101.5, 119, 112, 134, 102, 131, 98, 110, 110,
119, 126, 113.5, 102.5, 118.5, 119, 120, 121, 116.5, 114.5, 100,
106.5, 104.5, 113, 128, 118, 107.5, 103, 125.5, 133, 103.5, 121,
128, 115, 93.5, 107, 118.5, 110, 107, 110, 98, 112.5, 114.5,
96, 130, 104, 106, 104, 103, 119, 132, 105.5, 106.5, 98, 109,
135, 119.5, 104, 92, 106, 105.5, 107, 107, 113, 106, 104.5, 104,
115.5, 104.5, 112, 94, 107.5, 110, 108, 113, 112.5, 120, 105,
110, 112, 124.5, 116, 107, 105, 111.5, 108, 101.5, 129.5, 111,
106, 102, 119.5, 113, 111, 109, 109, 100, 101, 110, 113.5, 114.5,
107, 94, 126, 90, 109, 111, 120, 109, 116, 125, 120, 112, 119,
114.5, 104.5, 90, 114, 117, 110.2, 104.5, 100, 106, 109, 108,
108, 106.5, 111, 110, 129.5, 127, 108, 121, 117.5, 114, 101.5,
109, 102.5, 131, 125, 109, 94, 121, 113, 103), tasis2_e_v00 = c(138,
151, 134, 164, 138, 156, 144, 137, 130, 146, 131, 139, 122, 156,
141, 161, 137, 130, 152, 120, 154, 165, 138, 169, 147, 155, 152,
138, 136, 144, 123, 154, 138, 137, 123, 139, 145, 146, 145, 115,
123, 137, 146, 121, 145, 109, 130, 138, 137, 123, 146, 131, 131,
123, 123, 131, 145, 137, 146, 139, 160, 138, 109, 138, 178, 146,
130, 130, 138, 147, 145, 138, 154, 144, 139, 136, 138, 149, 123,
138, 130, 147, 154, 154, 122, 135, 139, 140, 146, 129, 145, 156,
137, 116, 161, 146, 154, 167, 138, 146, 138, 137, 126, 129, 128,
123, 138, 136, 121, 154, 146, 139, 138, 137, 148, 131, 146, 137,
149, 138, 173, 147, 130, 156, 153, 148, 152, 114, 124, 149, 146,
138, 131, 161, 143, 130, 155, 131, 131, 131, 144, 138, 146, 132,
139, 146, 122, 130, 124, 154, 162, 114, 167, 138, 132, 130, 147,
158, 153, 139, 145, 156, 140, 124, 131, 143, 146, 145, 123, 138,
138, 144, 155, 124, 145, 149, 139, 138, 131, 145, 130, 144, 160,
160, 139, 140, 123, 113, 123, 167, 157, 138, 113, 132, 146, 130,
137, 168, 143, 115, 138, 139, 129, 136, 146, 145, 140, 115, 123,
147, 145, 138, 138, 131, 135, 146, 131, 171, 147, 151, 176, 147,
146, 124, 167, 123, 129, 149, 144, 146, 125, 123, 130, 145, 122,
130, 146, 160, 131, 130, 139, 144, 126, 131, 106, 117, 153, 138,
100, 146, 115, 137, 131, 161, 145, 161, 114, 123, 123, 127, 154,
138, 146, 115, 140, 139, 122, 146, 162, 130, 118, 145, 158, 123,
147, 161, 139, 147, 106, 138, 131, 138, 143, 138, 133, 129, 131,
143, 136, 140, 147, 155, 146, 138, 146, 147, 134, 129, 145, 145,
136, 147, 146, 139, 145, 175, 153, 152, 138, 139, 131, 123, 152,
147, 124, 145, 154, 138, 148, 146, 146, 129, 147, 130, 164, 132,
145, 132, 146, 133, 144, 136, 145, 148, 138, 146, 138, 113, 131,
145, 146, 130, 146, 164, 138, 137, 139, 172, 130, 142, 165, 138,
145, 131, 131, 139, 130, 122, 130, 147, 154, 122, 130, 121, 137,
154, 132, 124, 153, 139, 146, 154, 138, 125, 124, 137, 147, 122,
145, 131, 183, 146, 115, 138, 143, 145, 149, 132, 152, 130, 163,
130, 146, 144, 117, 131, 121, 146, 130, 147, 169, 138, 133, 149,
123, 161, 130), tadias2_e_v00 = c(76, 71, 59, 63, 84, 67, 79,
76, 72, 88, 50, 65, 71, 60, 59, 78, 79, 64, 67, 53, 81, 93, 80,
103, 76, 77, 71, 79, 63, 80, 49, 87, 68, 69, 69, 72, 75, 88,
79, 69, 68, 67, 76, 75, 71, 67, 63, 76, 77, 60, 68, 83, 85, 71,
84, 65, 79, 59, 81, 73, 66, 72, 74, 68, 65, 80, 65, 96, 77, 82,
88, 60, 79, 78, 85, 73, 76, 63, 91, 72, 69, 84, 76, 80, 56, 84,
96, 83, 80, 84, 71, 89, 72, 77, 97, 81, 60, 76, 87, 80, 88, 87,
73, 71, 80, 78, 76, 75, 67, 73, 88, 69, 88, 83, 58, 65, 57, 71,
81, 75, 70, 87, 84, 82, 72, 86, 73, 71, 65, 82, 80, 68, 92, 72,
79, 79, 94, 87, 77, 64, 78, 85, 65, 78, 77, 81, 76, 68, 62, 77,
95, 78, 89, 78, 87, 68, 82, 65, 75, 81, 64, 57, 93, 66, 81, 80,
88, 84, 54, 72, 81, 69, 98, 76, 79, 79, 77, 84, 81, 65, 69, 76,
74, 75, 78, 74, 68, 68, 72, 85, 93, 72, 68, 68, 92, 71, 75, 74,
91, 81, 80, 78, 63, 71, 80, 75, 82, 61, 65, 81, 79, 63, 72, 59,
89, 72, 58, 89, 82, 88, 110, 81, 72, 80, 89, 72, 76, 82, 78,
79, 81, 76, 82, 56, 75, 55, 89, 75, 76, 63, 68, 79, 67, 61, 60,
61, 76, 71, 50, 68, 68, 63, 64, 62, 79, 81, 68, 62, 65, 78, 93,
82, 80, 72, 85, 69, 84, 68, 74, 80, 71, 84, 91, 57, 90, 71, 78,
61, 46, 82, 72, 81, 78, 60, 79, 71, 76, 60, 79, 66, 73, 66, 84,
85, 73, 86, 64, 67, 85, 79, 84, 88, 72, 66, 92, 78, 88, 69, 72,
73, 65, 57, 90, 65, 49, 83, 80, 77, 90, 73, 80, 74, 78, 76, 81,
81, 94, 74, 80, 73, 79, 82, 84, 83, 92, 65, 73, 58, 58, 83, 79,
64, 80, 98, 79, 79, 78, 89, 76, 86, 95, 76, 79, 84, 73, 69, 69,
68, 64, 101, 74, 68, 61, 75, 75, 73, 58, 77, 73, 74, 49, 91,
72, 56, 66, 71, 77, 72, 80, 96, 94, 60, 65, 57, 55, 79, 65, 73,
77, 87, 90, 64, 80, 72, 70, 84, 56, 60, 82, 72, 80, 65, 84, 83,
75, 86, 60), p17_total_v00 = c(7, 2, 9, 7, 12, 5, 8, 8, 14, 4,
8, 4, 14, 7, 9, 7, 12, 11, 10, 14, 10, 9, 14, 10, 9, 8, 8, 12,
9, 10, 7, 9, 7, 4, 6, 5, 5, 6, 3, 5, 6, 4, 10, 7, 8, 6, 6, 8,
4, 8, 6, 9, 6, 8, 8, 9, 4, 5, 5, 7, 5, 8, 6, 7, 6, 6, 6, 6, 4,
8, 2, 5, 7, 8, 7, 10, 12, 8, 9, 4, 6, 10, 5, 5, 11, 6, 4, 8,
8, 12, 11, 4, 9, 10, 13, 3, 5, 9, 5, 8, 4, 4, 12, 7, 5, 8, 8,
5, 7, 6, 5, 8, 4, 8, 11, 10, 8, 8, 9, 9, 6, 6, 7, 11, 6, 5, 7,
10, 8, 10, 6, 7, 7, 5, 11, 11, 6, 6, 6, 13, 4, 9, 4, 6, 5, 7,
7, 10, 5, 5, 8, 6, 5, 6, 7, 8, 8, 6, 6, 7, 2, 8, 8, 9, 5, 9,
5, 12, 8, 6, 7, 6, 10, 12, 7, 10, 7, 9, 4, 6, 12, 10, 8, 6, 9,
9, 9, 8, 4, 14, 7, 11, 11, 2, 12, 7, 9, 11, 11, 9, 6, 7, 14,
5, 4, 8, 5, 7, 7, 7, 12, 6, 8, 7, 2, 6, 6, 9, 7, 10, 8, 11, 9,
8, 6, 11, 9, 9, 7, 7, 4, 7, 5, 9, 9, 6, 6, 8, 8, 8, 3, 6, 6,
6, 11, 11, 6, 6, 7, 11, 11, 6, 8, 10, 7, 8, 8, 13, 5, 5, 4, 7,
7, 10, 9, 3, 5, 9, 9, 6, 3, 5, 4, 5, 5, 9, 5, 8, 5, 8, 10, 7,
12, 9, 9, 4, 7, 9, 3, 8, 3, 2, 6, 7, 4, 5, 10, 9, 3, 5, 5, 5,
9, 5, 9, 8, 12, 9, 8, 7, 5, 9, 6, 11, 10, 7, 9, 9, 6, 8, 3, 4,
10, 6, 8, 7, 9, 4, 8, 11, 6, 9, 10, 10, 6, 10, 6, 9, 5, 7, 6,
9, 7, 7, 9, 7, 6, 7, 2, 5, 4, 4, 5, 5, 7, 10, 5, 10, 8, 6, 10,
4, 7, 10, 6, 10, 9, 7, 8, 7, 7, 10, 5, 6, 5, 9, 8, 8, 6, 5, 3,
9, 5, 7, 5, 10, 9, 4, 7, 6, 13, 7, 3, 6, 6, 7, 4, 9, 9, 6, 5,
10, 8, 10, 6, 11, 10), geaf_tot_v00 = c(2517.48, 2769.23, 97.9,
5146.85, 664.34, 1557.11, 1678.32, 1300.7, 7574.83, 1678.32,
3543.12, 3188.81, 2293.71, 111.89, 4755.24, 5687.65, 3153.85,
2958.04, 2042.89, 1535.66, 1678.32, 1931.93, 432.63, 292.77,
2331, 6834.5, 2530.54, 1272.73, 909.09, 1986.01, 559.44, 2321.68,
3356.64, 559.44, 559.44, 86.71, 2097.9, 3384.62, 2349.65, 2713.29,
839.16, 4755.24, 1622.38, 615.38, 1678.32, 395.34, 2937.06, 4382.28,
2797.2, 2388.81, 8937.06, 1678.32, 2237.76, 5679.25, 3804.2,
1678.32, 1818.18, 839.16, 4643.36, 2531.47, 6414.92, 5622.38,
4895.1, 2377.62, 447.55, 1371.56, 1678.32, 0, 2834.5, 4335.66,
455.01, 1398.6, 6293.71, 559.44, 2237.76, 839.16, 4965.03, 923.08,
2517.48, 3482.52, 1958.04, 3356.64, 2937.06, 1608.39, 9860.14,
2797.2, 2293.71, 6853.15, 5034.97, 5559.44, 1678.32, 2937.06,
466.2, 1332.4, 1440.56, 83.92, 2517.48, 839.16, 839.16, 2013.99,
3034.97, 251.75, 6433.57, 1930.07, 643.36, 839.16, 5902.1, 2834.5,
3076.92, 3251.75, 4587.41, 93.24, 1076.92, 4895.1, 10349.65,
3356.64, 3356.64, 839.16, 699.3, 5524.48, 13986.01, 0, 3524.48,
1706.29, 2237.76, 3916.08, 279.72, 5995.34, 2517.48, 2536.13,
2517.48, 895.1, 279.72, 2237.76, 2314.69, 581.82, 27.97, 1230.77,
5118.88, 1818.18, 3076.92, 7160.84, 4191.14, 3636.36, 1461.54,
839.16, 1118.88, 1678.32, 447.55, 2382.28, 3356.64, 895.1, 3468.53,
4055.94, 1398.6, 3121.68, 186.48, 7370.63, 587.41, 671.33, 1980.42,
4475.52, 1818.18, 3356.64, 419.58, 1601.4, 1202.8, 1258.74, 1300.7,
1433.57, 55.94, 335.66, 1048.95, 2657.34, 350.58, 559.44, 6013.99,
1048.95, 951.05, 1678.32, 372.96, 5734.27, 671.33, 3650.35, 223.78,
7160.84, 1706.29, 559.44, 2853.15, 7780.89, 6951.05, 5601.4,
4335.66, 1678.32, 1006.99, 3216.78, 3475.52, 3104.9, 3118.88,
2769.23, 6242.42, 2256.41, 2517.48, 0, 1501.17, 6937.06, 4944.06,
5524.48, 923.08, 1678.32, 3776.22, 7496.5, 1370.63, 2797.2, 615.38,
4755.24, 279.72, 3356.64, 139.86, 671.33, 895.1, 9097.44, 8053.15,
139.86, 3174.83, 1444.29, 1594.41, 863.4, 3358.51, 1670.86, 1090.91,
1454.55, 2452.21, 3084.38, 1678.32, 231, 2517.48, 198.14, 4195.8,
2517.48, 1678.32, 1678.32, 5927.27, 3776.22, 2265.73, 4128.21,
2517.48, 2101.63, 7272.73, 1678.32, 1734.27, 3776.22, 167.83,
2386.01, 1678.32, 4219.11, 1659.67, 2800.93, 1286.71, 4055.94,
559.44, 1398.6, 2489.51, 3184.15, 1188.81, 1286.71, 671.33, 2713.29,
5874.13, 3412.59, 1468.53, 1525.41, 0, 339.39, 4820.51, 559.44,
157.34, 1118.88, 111.89, 839.16, 783.22, 2144.52, 1491.84, 8400,
2601.4, 923.08, 2279.72, 2055.94, 6853.15, 1822.84, 1678.32,
10069.93, 2601.4, 1384.62, 3356.64, 4475.52, 993.94, 391.61,
1454.55, 1146.85, 5734.27, 895.1, 2937.06, 839.16, 1832.17, 839.16,
1174.83, 993.01, 1118.88, 4475.52, 1538.46, 6293.71, 0, 2741.26,
1976.69, 1734.27, 10209.79, 1324.01, 111.89, 1720.28, 3398.6,
0, 6881.12, 335.66, 4461.54, 3412.59, 1070.4, 5594.41, 3356.64,
6489.51, 1846.15, 0, 2377.62, 4615.38, 3916.08, 3356.64, 419.58,
839.16, 3020.98, 3832.17, 839.16, 6153.85, 419.58, 302.1, 1685.78,
1398.6, 83.92, 2592.07, 839.16, 0, 3356.64, 0, 69.93, 1657.34,
1995.34, 419.58, 1557.11, 3860.14, 3566.43, 4405.59, 5930.07,
547.79, 629.37, 1441.49, 1607.46, 1135.66, 3524.48, 4377.62,
279.72, 0, 5594.41, 2573.43, 9006.99, 335.66, 1762.24, 2601.4,
8146.85, 3524.48, 2237.76, 2685.31, 1335.66, 1153.85, 1118.88,
1258.74, 419.58, 3636.36, 4160.84, 1678.32, 2212.12, 1398.6,
2517.48, 5594.41, 2517.48, 4979.02, 783.22, 4657.34, 559.44,
559.44, 1958.04, 2797.2, 773.89, 839.16, 6228.44, 2256.41, 419.58,
1678.32, 3286.71)), row.names = c(NA, 407L), class = "data.frame")
The columns to loop through
vars<-c( "peso1_v00", "cintura1_v00", "tasis2_e_v00", "tadias2_e_v00", "p17_total_v00", "geaf_tot_v00" )
The loop
for (v in vars) {
print(
boxplot(df[, v], main = v)
)
}
Then, there are generated several boxplots in the viewer. The problem is with my real database I have multiple plots, and I am looking for something to save it all at once. The solutions proposed in previous threads are not working
Thanks for the help in advance
To save each boxplot you could modify your loop like this:
for (v in vars) {
png(file=paste("plot",v,".png",sep=""))
boxplot(df[, v], main = v)
dev.off()
}

FCT_Collapse using a range

Im trying to use a range (160:280) instead of '160', '161' and so on. How would i do that?
group_by(disp = fct_collapse(as.character(disp), Group1 = c(160:280), Group2 = c(281:400)) %>%
summarise(meanHP = mean(hp)))
Error: Problem adding computed columns in `group_by()`.
x Problem with `mutate()` column `disp`.
i `disp = `%>%`(...)`.
x Each input to fct_recode must be a single named string. Problems at positions: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 17```
For range of values it is better to use cut where you can define breaks and labels.
library(dplyr)
library(forcats)
mtcars %>%
group_by(disp = cut(disp, c(0, 160, 280, 400, Inf), paste0('Group', 1:4))) %>%
summarise(meanHP = mean(hp))
# disp meanHP
# <fct> <dbl>
#1 Group1 93.1
#2 Group2 143
#3 Group3 217.
#4 Group4 217.
So here 0-160 becomes 'Group1', 160-280 'Group2' and so on.
With fct_collapse you can do -
mtcars %>%
group_by(disp = fct_collapse(as.character(disp), Group1 = as.character(160:280), Group2 = as.character(281:400))) %>%
summarise(meanHP = mean(hp)) %>%
suppressWarnings()
However, this works only for exact values which are present so 160 would be in group1 but not 160.1.
We could also do
library(dplyr)
library(stringr)
mtcars %>%
group_by(disp = cut(disp, c(0, 160, 280, 400, Inf), strc('Group', 1:4))) %>%
summarise(meanHP = mean(hp))

Reformat daily stock and return data to weekly/monthly

I have some stock data together with some returns that are presented below.
Now I would like to coerce both the daily price changes (open, high, low, close, volume, adj. close) and the returns given to weekly or monthly values.
I know that the weekly prices can be obtained by xts::to.weekly(), but this drops the return. I don't know the exact mechanism behind the to.weekly function, but the returns need to be summarized with the sum function (I'm thinking of using xts::apply.weekly()), but then this would not be consistent with the stock price data....
How can this transition to weekly or monthly timescale be achieved efficiently?
Data <-
structure(c(64.5, 67, 72, 76, 75.75, 72, 75.5, 76, 76, 78, 78,
77.5, 79.25, 80, 76.25, 84, 89.75, 90.75, 92.25, 95.75, 94.5,
95, 92, 95.75, 100, 98, 104.25, 101.25, 100.25, 96.5, 94.75,
89, 94, 91.25, 99.25, 100.25, 100.25, 98, 96.5, 94.75, 97.5,
96.25, 99.25, 97, 98, 98.75, 97.25, 98.75, 100.25, 100.25, 103.25,
105.75, 108.5, 108.25, 103.75, 101.5, 99.75, 100, 99, 94.5, 99,
101.5, 105, 64.75, 73.25, 76.5, 76.75, 76, 75.75, 76, 76, 76,
80.75, 79, 79.5, 83, 80.5, 76.75, 91.5, 92.75, 94.75, 100.25,
96, 97.5, 96.75, 92, 100, 101.75, 104, 105, 103.25, 100.75, 99,
95.5, 92.75, 94, 97.75, 103.75, 101, 100.25, 99.5, 97.75, 96.75,
98, 99, 100, 100.75, 99.25, 98.75, 98, 102.25, 101, 103, 105,
109, 110.5, 108.25, 105, 102.25, 100.75, 100, 99.75, 98.75, 102.5,
103, 107.25, 60.75, 66.75, 71.25, 74.25, 72.25, 71.5, 74.25,
76, 76, 77, 75.75, 76, 79, 75.75, 73.25, 82, 88.75, 89.5, 91.75,
92.25, 92.75, 92, 92, 94, 97.75, 96.5, 98.5, 99.25, 93.5, 94,
88.25, 87.5, 91, 91, 98.75, 98.5, 100.25, 95.75, 95.5, 90.75,
96.75, 96, 95.25, 97, 95.75, 95.75, 96.75, 98.5, 97.25, 100.25,
102.5, 105.5, 107.5, 103.5, 102.75, 97.5, 98.25, 100, 94, 94.25,
98, 100, 103.75, 64.25, 72.75, 75.75, 75, 73.75, 75.5, 76, 76,
76, 79, 76, 79.25, 81.25, 76.75, 75.75, 88, 90.25, 93.75, 97.5,
95, 95, 92, 92, 100, 97.75, 102.75, 99.75, 100.25, 97.25, 94.5,
89, 91.75, 92.5, 97, 99.5, 100.25, 100.25, 96.75, 96, 96, 97.5,
98, 95.5, 100.75, 98, 96.75, 98, 100.25, 99.5, 102.25, 103.5,
108, 109.25, 104, 102.75, 99, 100, 100, 94.5, 97.5, 102, 103,
104.5, 6808900, 8180500, 5628500, 3238900, 3765800, 3177100,
887600, 0, 0, 3923200, 2425700, 3331200, 4058600, 3682800, 3293500,
10525000, 5664200, 3982600, 4702300, 6479800, 2565300, 2480500,
0, 3653000, 3400, 4010500, 5145800, 2782200, 3925100, 2770700,
4618500, 2712300, 1675400, 3331500, 5343000, 1169700, 0, 2095400,
1016600, 3642600, 3729400, 3575300, 3396900, 1963400, 3547300,
1865100, 2496300, 3226800, 2333200, 4285900, 3933000, 7400700,
3325200, 1848400, 21000, 4273700, 1910400, 0, 3168000, 2356000,
2184800, 1950300, 2649900, 51.5865, 58.4112, 60.8199, 60.2178,
59.2141, 60.6192, 61.0207, 61.0207, 61.0207, 63.4294, 61.0207,
63.6301, 65.2359, 61.6228, 60.8199, 70.6555, 72.462, 75.2722,
78.2831, 76.2758, 76.2758, 73.8671, 73.8671, 80.2903, 78.4838,
82.4983, 80.0896, 80.4911, 78.0824, 75.8744, 71.4584, 73.6664,
74.2686, 77.8816, 79.8889, 80.4911, 80.4911, 77.6809, 77.0787,
77.0787, 78.2831, 78.6845, 76.6773, 80.8925, 78.6845, 77.6809,
78.6845, 80.4911, 79.8889, 82.0969, 83.1005, 86.7136, 87.7172,
83.5019, 82.4983, 79.4874, 80.2903, 80.2903, 75.8744, 78.2831,
81.8961, 82.699, 83.9034, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.086956169, -0.022499605, 0.051150683,
-0.029196965, 0.005013135, -0.029925048, -0.028277819, -0.058201449,
0.030899097, 0.00817469, 0.048647746, 0.025773739, 0.007537968,
0, -0.034913177, -0.007752227, 0, 0.015625588, 0.005127543, -0.025509471,
0.054973245, -0.027295485, -0.012754736, 0.012919521, 0.022960049,
-0.007481572, 0.027638383, 0.012224579, 0.043478679, 0.011573732,
-0.048055569, -0.012018888, -0.03649651, 0.010100972, 0, 0, 0,
0.046153001, 0.009803886, 0.014563659), .Dim = c(63L, 7L), .Dimnames = list(
NULL, c("Open", "High", "Low", "Close", "Volume", "Adj.Close",
"Return")), index = structure(c(1238544000, 1238630400, 1238716800,
1238976000, 1239062400, 1239148800, 1239235200, 1239321600, 1239580800,
1239667200, 1239753600, 1239840000, 1239926400, 1240185600, 1240272000,
1240358400, 1240444800, 1240531200, 1240790400, 1240876800, 1240963200,
1241049600, 1241136000, 1241395200, 1241481600, 1241568000, 1241654400,
1241740800, 1.242e+09, 1242086400, 1242172800, 1242259200, 1242345600,
1242604800, 1242691200, 1242777600, 1242864000, 1242950400, 1243209600,
1243296000, 1243382400, 1243468800, 1243555200, 1243814400, 1243900800,
1243987200, 1244073600, 1244160000, 1244419200, 1244505600, 1244592000,
1244678400, 1244764800, 1245024000, 1245110400, 1245196800, 1245283200,
1245369600, 1245628800, 1245715200, 1245801600, 1245888000, 1245974400),
tzone = "UTC", tclass = "Date"), class = c("xts", "zoo"), .indexCLASS = "Date",
tclass = "Date", .indexTZ = "UTC", tzone = "UTC")
Use period.apply (or apply.daily, apply.weekly, etc.) with your own custom function. Something like:
library(quantmod) # for Op, Hi, Lo, Cl, and Vo functions
myFun <- function(x) {
# need coredata, so c.xts will not be dispatched
cx <- coredata(x)
c(Open = first(Op(cx)),
Hi = max(Hi(cx)),
Low = min(Lo(cx)),
Close = last(cx[,"Close"]),
Volume = sum(Vo(cx)),
Adj.Close = last(cx[,"Adj.Close"]),
Return = sum(cx[,"Return"]))
}
out <- period.apply(Data, endpoints(Data, "months"), myFun)
# Open Hi Low Close Volume Adj.Close Return
# 2009-04-30 64.5 100.25 60.75 92.0 88802000 73.8671 0.0000000
# 2009-05-29 92.0 105.00 87.50 95.5 58597300 76.6773 0.0486306
# 2009-06-26 97.0 110.50 94.00 104.5 54739400 83.9034 0.1222869

ggvis barchart using dates as x axis

I have been switching over from ggplot to ggvis when working with shiny apps. I have figured out a lot but am really stumped when it comes to bar graphs. I have a timeseries with dates and values. I simply want bars instead of points for each value (I would ideally like to be able to plot multiple semi-transparent bars if anyone has had success there please share) but here I wanted to get one bar working.
Works with layer_points()
df %>% ggvis(~date, ~x) %>% layer_points() %>% scale_datetime("x")
Doesnt work with layer_bars()
df %>% ggvis(~date, ~x) %>% layer_bars() %>% scale_datetime("x")
Data I am using...
structure(list(date = structure(c(7680, 7687, 7694, 7701, 7708,
7715, 7722, 7729, 7736, 7743, 7750, 7757, 7764, 7771, 7778, 7785,
7792, 7799, 7806, 7813, 7820, 7827, 7834, 7841, 7848, 7855, 7862,
7869, 7876, 7883, 7890, 7897, 7904, 7911, 7918, 7925, 7932, 7939,
7946, 7953, 7960, 7967, 7974, 7981, 7988, 7995, 8002, 8009, 8016,
8023, 8030, 8037, 8044, 8051, 8058, 8065, 8072, 8079, 8086, 8093,
8100, 8107, 8114, 8121, 8128, 8135, 8142, 8149, 8156, 8163, 8170,
8177, 8184, 8191, 8198, 8205, 8212, 8219, 8226, 8233, 8240, 8247,
8254, 8261, 8268, 8275, 8282, 8289, 8296, 8303, 8310, 8317, 8324,
8331, 8338, 8345, 8352, 8359, 8366, 8373, 8380, 8387, 8394, 8401,
8408, 8415, 8422, 8429, 8436, 8443, 8450, 8457, 8464, 8471, 8478,
8485, 8492, 8499, 8506, 8513, 8520, 8527, 8534, 8541, 8548, 8555,
8562, 8569, 8576, 8583, 8590, 8597, 8604, 8611, 8618, 8625, 8632,
8639, 8646, 8653, 8660, 8667, 8674, 8681, 8688, 8695, 8702, 8709,
8716, 8723, 8730, 8737, 8744, 8751, 8758, 8765, 8772, 8779, 8786,
8793, 8800, 8807, 8814, 8821, 8828, 8835, 8842, 8849, 8856, 8863,
8870, 8877, 8884, 8891, 8898, 8905, 8912, 8919, 8926, 8933, 8940,
8947, 8954, 8961, 8968, 8975, 8982, 8989, 8996, 9003, 9010, 9017,
9024, 9031, 9038, 9045, 9052, 9059, 9066, 9073), class = "Date"),
x = c(-0.034038302, 0.122310949, -0.002797319, 0.026515253,
0.039961798, 0.034473263, 0.00549937, -0.024125944, 0.000132490000000001,
0.011038357, -0.02135072, 0.030663311, -0.008915551, 0.004855042,
0.01563688, -0.007397493, 0.013569146, -0.004968811, -0.00250391,
0.014624532, 0.036937453, -0.023685917, 0.018921356, -0.003066779,
-0.009217771, 0.005317513, 0.010378968, 0.001580798, -0.015085972,
-0.000121644000000001, 0.020468644, 0.007925229, 0.007721276,
-0.003123545, -0.018317891, -0.014900591, 0.003260844, -0.001565358,
-0.014833886, 0.00366766, 0.014297139, -0.00725552, 0.012207931,
0.024035152, -0.024195095, -0.0043564, 0.000847468, 0.033031596,
0.023685033, 0.025143071, 0.046264348, 0.038285177, -0.009180356,
-0.01630399, -0.010131294, -0.009939386, -0.007620427, 0.013062259,
0.009912238, 0.000192973, -0.01683559, -0.002627549, 0.019836063,
-0.019946159, -0.020124331, 0.012921737, 0.034604405, -0.020774015,
0.00334805, 0.002271156, -0.018676732, 0.019160923, -0.01945997,
-0.014342636, -0.004867796, -0.010002446, -0.004372991, 0.023164369,
0.019824112, -0.00321832, -0.015785746, 0.040836652, 0.00148831,
0.012084485, -0.009603897, -0.004642148, -0.008399234, 0.010463218,
0.000256571000000001, -0.01978405, -0.003439498, -0.015669975,
0.026180724, 0.020373255, 0.019160773, 0.00692683, 0.010215506,
0.010861939, 0.012041143, 0.025734568, -0.004828156, 0.006914552,
-0.00720089, -0.000538489999999999, -0.008479448, 0.022926604,
0.002131842, -0.003688597, 0.025325639, -0.009562293, -0.024336741,
0.012907537, 0.004339383, 0.010744364, -0.013058765, -0.003672014,
-0.023887493, 0.01062259, 0.02088054, -0.035249878, -0.001462821,
0.01904368, -0.001308787, 0.009203217, 0.019856479, 0.011296979,
0.010039545, -0.01559142, 0.006083419, -0.017958978, -0.007488063,
0.01236649, -0.004459064, -0.004375386, 0.025500722, 0.005557851,
0.008444321, 0.002827649, 0.020320308, 0.031611803, -0.010199803,
-0.009425874, 0.007942729, -2.59379999999999e-05, 0.016669077,
-0.011666062, 0.022835386, -0.025599107, 0.013562535, -0.018365192,
0.018148786, 0.016649144, -0.009530455, 0.012996597, 0.002034778,
-0.005926478, -0.004897238, -0.004419719, 0.010848926, -0.006039757,
-0.030287605, 0.019221837, 0.001808161, -0.009566133, 0.005009292,
0.005365023, -0.004879922, -0.024637933, -0.0186584, 0.004786059,
-0.008245254, -0.000106243, -0.001714888, -0.017804006, -0.021200061,
0.003812757, 0.021940886, 0.002270448, -0.015417493, -0.045754612,
-0.003468442, -0.006242659, 0.022383824, -0.018753927, 0.008577571,
0.008655048, 0.02374636, 0.029522811, 0.009946946, 0.015419714,
-0.016714623, -0.014616188, 0.019670855, -0.038979063, 0.020491563,
-0.009640674, 0.046051144, -0.021434575, 0.000190443999999998,
-0.029013969), id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172,
173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200)), .Names = c("date", "x", "id"), row.names = 53:252, class = "data.frame")
Set format df$date as character:
df$date <- as.character(df$date)
and then:
df %>% ggvis(~date, ~x) %>% layer_bars()

Resources