Using lapply to Sample dataframe, include new column and reorder columns - r

df<-structure(list(BBAS3 = c(22.85, 22.78, 22.8, 22.22, 22.51, 21.11,
20.84, 20.79, 20.67, 20.9, 20.95, 20.7, 21.03, 21.96, 21.9, 21.8,
21.9, 22.49, 22.65, 22.9, 22.19, 22.44, 21.66, 22.5, 22.96, 23.36,
23.64, 23.46, 23.85, 23.74, 23.9, 23.97, 23.95, 23.85, 23.66,
23.52, 23.5, 23.57, 23.28, 23.09, 23.74, 24.09, 23.96, 23.93,
23.07, 23.54, 24.04, 24.82, 24.58, 24.51, 23.88, 23.16, 23.79,
24.61, 25.12, 26, 25.87, 25.44, 25.6, 27.04, 26.8, 27.52, 27.65,
28.36, 28.77, 28.59, 28.63, 28.16, 27.58, 27.49, 27.6, 27.28,
26.95, 27.09, 27.05, 27.29, 26.74, 26.61, 26.04, 26.05, 25.68,
25.8, 25.49, 25.05, 25.33, 25.24, 25.17, 25.16, 25.11, 24.88,
25.44, 24.74, 24.78, 24.97, 25.25, 24.54, 24.64, 24.4, 23.61,
23.24, 23.1, 22.89, 23.29, 23.42, 23.03, 22.57, 22.4, 22.05,
21.88, 22.09, 21.9, 21.47, 21, 20.71, 20.71, 21.13, 20.86, 20.17,
20.46, 20.67, 21.24, 21.29, 21.54, 21.42, 21.06, 20.74, 20.29,
19.56, 19.66, 20.38, 20.93, 21.24, 20.8, 21.05, 20.82, 20.64,
20.73, 20.98, 21.14, 20.89, 20.46, 20.73, 20.56, 20.37, 19.81,
19.27, 19.41, 18.85, 18.73, 18.76, 18.91, 18.63, 19.18, 20.33,
20.31, 19.75, 19.55, 19.5, 19.34, 19.38, 19.41, 20.09, 20.74,
21.09, 21.03, 20.93, 20.5, 21.17, 21.7, 21.49, 22.08, 22.17,
22.7, 23.15, 23.03, 23.45, 24.29, 24.31, 24.2, 24.16, 24.19,
23.8, 24, 23.41, 22.73, 22.29, 22.82, 22.7, 22.96, 22.83, 23,
22.95, 22.01, 22.39, 22.54, 22.7, 22.55, 22.75, 23.25, 23.66,
24.19, 23.99, 24.03, 24.23, 24.93, 25.43, 25.15, 25.61, 25.58,
25.45, 24.92, 24.4, 24.01, 23.88, 24.43, 24.97, 24.96, 24.79,
24.3, 24.07, 23.88, 24.03, 24.21, 24.22, 23.82, 23.47, 23.8,
23.86, 23.77, 24.02, 24.3, 24.39, 23.95, 23.84, 23.59, 23.72,
23.75, 23.33, 23.16, 22.49, 22.5, 22.78, 22.4, 21.52, 21.72,
21.33, 21.61, 21.08, 21.13, 21.09, 20.94, 21.19, 21.31, 21.12,
21.52, 21.61, 21.96, 22.16, 21.88, 22.49, 22.58, 22.71, 22.96,
23.2, 23.74, 23.79, 23.65, 23.85, 23.01, 23.29, 23.65, 23.42,
23.16, 23.03, 23.3, 22.85, 22.67, 22.19, 22.14, 22.32, 22.14,
21.43, 20.35, 19.73, 19.82, 19.98, 20.28, 20.11, 20.11, 19.97,
19.55, 19.63, 19.28, 19.29, 19.15, 19.49, 19.15, 19.15, 19.13,
18.8, 18.28, 18.36, 18.31, 18.28, 18.41, 18.43, 18.07, 18.22,
18.66, 19.53, 20.01, 19.52, 20.08, 18.85, 19.06, 19.04, 18.94,
19.31, 18.94, 19.14, 19.74, 19.74, 19.92, 20.04, 19.83, 20.09,
20.1, 19.52, 19.81, 19.83, 20.44, 21.33, 21.6, 21.83, 21.75,
21.57, 22.44, 22.41, 22.27, 22.98, 23.07, 23.22, 23.01, 22.56,
22.91, 23.05, 22.65, 22.19, 21.71, 21.55, 21.34, 20.82, 20.11,
20.21, 19.93, 20.11, 20.35, 20.69, 20.24, 19.8, 19.87, 20.17,
19.93, 19.99, 20.19, 20.14, 19.8, 19.22, 20.04, 20.68, 20.01,
20.43, 20.14, 20.38, 19.78, 18.89, 18.99, 18.65, 18.82, 18.5,
17.61, 16.47, 16.85, 16.72, 17.04, 17.02, 16.65, 15.57, 15.69,
16.08, 15.93, 15.87, 16.15, 16.63, 17.02, 17.06, 17.06, 16.81,
16.7, 16.05, 16.08, 15.95, 16.34, 17, 17.27, 17.43, 17.5, 16.81,
16.17, 16.01, 16.31, 16.35, 16.35, 16.2, 16.18, 15.85, 16.25,
16.82, 16.86, 16.79, 17.15, 17.37, 17.53, 17.38, 17.29, 18.05,
18.01, 16.98, 16.35, 17.19, 17.3, 17.95, 18.76, 18.77, 18.78,
19.26, 19.22, 19.05, 19, 19.28, 19.82, 19.79, 19.54, 19.36, 19.84,
19.99, 20.26, 20.03, 19.97, 19.65, 20.1, 20.59, 21.16, 20.67,
20.36, 20.24, 20.28, 20.34, 21.62, 21.73)), row.names = c(NA,
-460L), class = c("tbl_df", "tbl", "data.frame"))
With this data frame I create a list of dataframe with the code bellow:
samples_size <- c(9,7,5,3)
list_of_df <- lapply(samples_size,function(i)df %>% slice(1:i))
list_of_df
Now I have this vector bellow which will be my new column to included in each dataframe of the list list_of_df respecting the sample size:
time=seq(samples_size[i],1)
The Final result should be a list of dataframes like this:
list_of_df[[1]]<-cbind(list_of_df[[1]],seq(samples_size[1],1))
list_of_df[[1]]<-cbind(list_of_df[[2]],seq(samples_size[2],1))
list_of_df[[1]]<-cbind(list_of_df[[3]],seq(samples_size[3],1))
list_of_df[[1]]<-cbind(list_of_df[[4]],seq(samples_size[4],1))
And then, after this I would like to put the new column in the first position.
Is it possible to do all of these steps by using the first code above with lapply function :
list_of_df <- lapply(samples_size,function(i)df %>% slice(1:i))
and using dplyr Package??

Yes, and there is no need for dplyr:
lapply(samples_size, function(i) cbind(time = i:1, df[1:i, ]))
For instance, the first element will be
# [[1]]
# time BBAS3
# 1 9 22.85
# 2 8 22.78
# 3 7 22.80
# 4 6 22.22
# 5 5 22.51
# 6 4 21.11
# 7 3 20.84
# 8 2 20.79
# 9 1 20.67
As I was saying in the comment, lapply takes elements of sample_size one by one, in this case they are called i, and the manually defined anonymous function constructs some kind of result. Then all the results are returned a a list (contrary to sapply, which would try to merge the results to, say, a vector). So then this time column is simply i:1, which is a short way to write seq(i, 1), cbind stands for column which, which is what you are after, and by putting time = i:1 we make it as the first column in every intermediate result. Lastly, df[1:i, ] gives the first i rows of df, and, in this case, is a simple base R analogue of slice.

Related

Ploting red deciles in Q-Q plot stat_qq() or geom_qq()

I'm trying to compare a distribution against theoretical normal distribution but I would like to represents the decimal quantiles as red in the Q-Q plot.
This is the numeric array I'm using (as a df).
structure(list(v1 = c(84.01, 86.88, 48.5, 80.28, 63.85, 81.95,
8.94, 59.16, 35.16, 49.6, 56.16, 19.71, 63.03, 64.82, 2.92, 46.69,
42, 63.83, 53.29, 67.79, 15.87, 37.95, 52.99, 52.11, 66.14, 68.61,
61.19, 44.9, 54.8, 61.81, 80.9, 26.17, 12.7, 57.51, 73.41, 54.25,
55.61, 55.64, 57.69, 67.77, 23.21, 74.23, 29.43, 52.08, 41.1,
58.65, 55.25, 79.08, 71.39, 32.29, 66.9, 60.52, 100, 43.34, 47.69,
65.64, 75.9, 59.95, 55.12, 37.57, 60.76, 79.82, 55.67, 43.17,
56.56, 39.87, 65.32, 53.82, 57.76, 26.88, 62.83, 42.71, 73.82,
55.02, 73.52, 68.9, 60.82, 52.16, 61.34, 57.59, 19.71, 74.17,
63.93, 59.88, 55.47, 43.19, 45.17, 64.23, 99.18, 53.25, 58, 73.66,
100, 58.83, 86.6, 54.83, 58.13, 68.57, 56.17, 59.73, 47.02, 33.97,
60.2, 60.53, 47.18, 54.72, 49.71, 35.29, 62.25, 44.07, 46.35,
17.29, 26.93, 60.26, 77.35, 59.18, 71.83, 72.01, 58.78, 29.14,
62.56, 23.41, 39.82, 56.27, 46.55, 60.05, 80.74, 15.99, 58.64,
37.43, 60.38, 48.77, 54.41, 49.4, 36.05, 35.17, 80.04, 31.64,
56.2, 39.35, 10.61, 75.99, 51.69, 59.65, 52.58, 64.76, 76.07,
43.96, 66.95, 29.45, 43.18, 30.99, 51.22, 30.45, 73.49, 58.92,
67.22, 51.68, 62.56, 64.29, 46.11, 72.86, 66.33, 56.27, 62.04,
49.68, 46.44, 49.3, 66.93, 43.86, 12.72, 44.43, 60.62, 33.98,
83.57, 50.37, 36.96, 54.04, 30.47, 28.46, 48.35, 35.64, 71.47,
76.1, 7.32, 3.36, 83.27, 52.11, 90.43, 22.85, 7.9, 52.19, 41.96,
23.22, 42.86, 30.83, 54.66, 63.9, 46.04, 43.69, 84.14, 50.09,
65.29, 42.9, 72.92, 60.2, 45.36, 51.76, 58.7, 36.84, 77.72, 21.04,
53.21, 68.87, 12.22, 63.93, 18.57, 74.93, 65.3, 79.18, 38.03,
55.69, 73.93, 63.33, 93.97, 34.99, 45.87, 61.12, 47.95, 40.82,
54.1, 69.17, 54.9, 41.72, 76.39, 61.75, 79.3, 29.62, 41.29, 33.33,
52.31, 31.04, 65.94, 23.29, 64.27, 63.71, 73.43, 68.94, 68.85,
68.39, 39.13, 65.16, 61.77, 88.54, 76.29, 78.85, 44.97, 12.35,
90.31, 63.24, 77.85, 58.5, 81.05, 85.38, 74.16, 78.56, 54.86,
71.15, 62.7, 64.49, 27.32, 45.71, 56.29, 60.76, 90, 63.91, 71.72,
20.42, 45.02, 14.21, 54.64, 68.88, 71.67, 37.67, 53.88, 58.8,
33.86, 57.98, 57.84, 73.74, 39.83, 40.69, 54.66, 18.08, 43.79,
31.05, 89.34, 46.65, 24.99, 64.33, 51.87, 65.17, 40.04, 69.41,
13.89, 61.99, 44.14, 65.46, 47.14, 27.88, 52.46, 12.69, 45.41,
84.13, 59.48, 40.2, 40.76, 42.66, 35.56, 57.52, 41.17, 60.02,
44.58, 1.76, 35.8, 70.61, 20.74, 1.78, 60.11, 70.64, 26.04, 33.58,
61.88, 12.38, 48.17, 27.09, 75.23, 28.85, 53.25, 44.19, 64.56,
17.12, 51.22, 66.02, 43.06, 58.71, 55.65, 27.52, 45.28, 44.83,
74.25, 58.35, 23.1, 58.52, 54.1, 57.74, 47.61, 17.25, 57.44,
70.38, 43.69, 89.84, 72.9, 57.53, 33.53, 18.08, 41.71, 52.07,
46.63, 42.64, 41.98, 27.74, 72.13, 61.92, 83.65, 22.42, 62.47,
13.49, 68.39, 48.94, 72.79, 49.76, 63.05, 85, 45.58, 59.58, 57.94,
65.93, 65.26, 35.56, 65.71, 62.17, 21.07, 53.33, 72.97, 36.32,
55.38, 68.96, 66.11, 56.05, 70.68, 89.05, 73.7, 85.43, 88.74,
51.16, 49.83, 63.85, 45.61, 29.15, 49.93, 62.9, 61.39, 69.17,
6.61, 63.66, 76.21, 56.85, 49.86, 68.41, 75.94, 67.88, 62.25,
26.8, 74.27, 76.48, 46.25, 73.84, 47.21, 60.76, 42.17, 45.73,
41.4, 67.04, 48.28, 63.73, 65.9, 36.62, 74.91, 50.11, 24.21,
91.45, 78.71, 100, 27.59, 78.42, 38.69, 21.68, 0, 44.85, 59.28,
45.75, 36.84, 73.91, 41.8, 66, 74.88, 59.25, 54.7, 44.39, 40.95,
42.03, 66.93, 38, 72.08, 48, 41.7, 72.1, 64.23, 14.18, 43.53,
57.81, 52.68, 45.73, 97.12, 18.98, 57.12, 48.33, 18.94, 60.6,
52.05, 67.09, 72.89, 64.16, 57.79, 45.62, 55.02, 48.86, 60.74,
7.35, 56.31, 60.51, 49, 67.56, 84.62, 15.98, 54.67, 65.72, 65.79,
70.55, 74.18, 55.72, 57.89, 54.67, 39.83, 21.2, 78)), class = "data.frame", row.names = c(NA,
-507L))
This is to generate the Q-Q plot
example%>%
ggplot(aes(sample=v1)) +
stat_qq() + stat_qq_line()
# + add deciles colour='red' ?
How can I colour as red the deciles?
First create deciles using the ntile function. After that you can color the first decile by filtering that data and color them red. You can use the following code:
library(tidyverse)
example <- example %>% mutate(decile = ntile(v1, 10))
ggplot() +
geom_qq(example, mapping = aes(sample=example$v1),col=ifelse(example$decile == 1, "red", "black")[order(example$v1)]) +
geom_qq_line(aes(sample=example$v1))
Output:
Thanks to #Quinten answer I could manage to get the decile standing out from the qq points. So I added the ntile()function and calculated the changing points (real deciles) and that's the solution:
library(tidyverse)
example <- example %>%
mutate(decile = ntile(v1, 10)) %>%
arrange(v1) %>%
mutate(difs = decile - lag(decile)) %>%
mutate(difs= ifelse(is.na(difs),1,difs))
example %>%
ggplot(aes(sample=v1)) +
geom_qq(col=ifelse(example$difs == 1, "red", "black"),
alpha=ifelse(example$difs == 1, 1, 0.33),
size=ifelse(example$difs == 1, 1.5, 1)) +
geom_qq_line()

Trouble finding correct peaks when using pracma::findpeaks in R

I am having trouble getting the correct peaks using findpeaks
dat <- structure(list(Temp = c(36.36, 36.37, 36.38, 36.37, 36.37, 36.35,
36.34, 36.33, 36.34, 36.33, 36.32, 36.31, 36.3, 36.29, 36.28,
36.27, 36.27, 36.28, 36.27, 36.25, 36.24, 36.22, 36.22, 36.2,
36.19, 36.2, 36.2, 36.22, 36.22, 36.21, 36.21, 36.21, 36.21,
36.21, 36.21, 36.22, 36.22, 36.23, 36.24, 36.24, 36.24, 36.24,
36.25, 36.25, 36.24, 36.24, 36.23, 36.23, 36.22, 36.22, 36.21,
36.2, 36.19, 36.19, 36.19, 36.2, 36.2, 36.21, 36.22, 36.23, 36.23,
36.23, 36.23, 36.23, 36.24, 36.25, 36.24, 36.24, 36.24, 36.24,
36.25, 36.25, 36.27, 36.27, 36.28, 36.28, 36.27, 36.26, 36.26,
36.26, 36.25, 36.25, 36.25, 36.24, 36.24, 36.24, 36.24, 36.23,
36.22, 36.21, 36.21, 36.2, 36.2, 36.19, 36.19, 36.18, 36.18,
36.18, 36.18, 36.18, 36.17, 36.17, 36.17, 36.17, 36.17, 36.18,
36.18, 36.19, 36.18, 36.19, 36.19, 36.19, 36.19, 36.19, 36.18,
36.18, 36.16, 36.16, 36.15, 36.15, 36.15, 36.14, 36.12, 36.11,
36.11, 36.11, 36.11, 36.11, 36.1, 36.1, 36.1, 36.1, 36.11, 36.11,
36.11, 36.11, 36.1, 36.1, 36.09, 36.09, 36.09, 36.09, 36.09,
36.09, 36.1, 36.11, 36.12, 36.12, 36.12, 36.12, 36.12, 36.12,
36.13, 36.13, 36.13, 36.14, 36.14, 36.14, 36.13, 36.13, 36.13,
36.11, 36.1, 36.09, 36.09, 36.1, 36.11, 36.15, 36.17, 36.24,
36.29, 36.43, 36.51, 36.7, 36.8, 37.01, 37.14, 37.41, 37.56,
37.84, 38, 38.33, 38.5, 38.84, 39.01, 39.36, 39.55, 39.91, 40.1,
40.48, 40.79, 40.98, 41.43, 41.62, 41.99, 42.18, 42.56, 42.74,
43.13, 43.32, 43.7, 43.88, 44.15, 44.33, 44.69, 45.07, 45.25,
45.75, 45.93, 46.3, 46.48, 46.84, 47.03, 47.43, 47.63, 48.01,
48.19, 48.54, 48.7, 48.99, 49.12, 49.35, 49.54, 49.63, 49.77,
49.82, 49.88, 49.89, 49.91, 49.91, 49.9, 49.9, 49.86, 49.83,
49.77, 49.73, 49.65, 49.62, 49.53, 49.44, 49.39, 49.29, 49.24,
49.14, 49.08, 48.96, 48.9, 48.78, 48.71, 48.59, 48.53, 48.41,
48.35, 48.23, 48.18, 48.05, 47.98, 47.85, 47.79, 47.66, 47.59,
47.47, 47.32, 47.26, 47.12, 47.05, 46.92, 46.85, 46.73, 46.68,
46.56, 46.49, 46.37, 46.31, 46.18, 46.13, 46.02, 45.97, 45.88,
45.83, 45.77, 45.75, 45.73, 45.74, 45.81, 45.85, 45.97, 46.03,
46.17, 46.33, 46.43, 46.65, 46.76, 47.01, 47.13, 47.4, 47.54,
47.81, 48.14, 48.29, 48.58, 48.73, 49.04, 49.2, 49.53, 49.7,
50.03, 50.36, 50.52, 50.86, 51.03, 51.39, 51.65, 51.9, 52.06,
52.5, 52.87, 53.05, 53.41, 53.59, 53.82, 54, 54.37, 54.7, 55.06,
55.42, 55.61, 55.97, 56.15, 56.49, 56.65, 56.94, 57.06, 57.29,
57.47, 57.55, 57.68, 57.74, 57.81, 57.83, 57.83, 57.82, 57.78,
57.75, 57.66, 57.54, 57.48, 57.35, 57.28, 57.12, 57.03, 56.85,
56.76, 56.57, 56.47, 56.25, 56.15, 55.94, 55.72, 55.62, 55.35,
55.24, 55.01, 54.9, 54.68, 54.56, 54.32, 54.2, 53.96, 53.84,
53.59, 53.47, 53.23, 53.01, 52.9, 52.71, 52.69, 52.55, 52.49,
52.39, 52.35, 52.3, 52.28, 52.28, 52.34, 52.39, 52.45, 52.44,
52.56, 52.61, 52.72, 52.79, 52.93, 52.97, 53.11, 53.29, 53.37,
53.54, 53.62, 53.79, 53.88, 54.06, 54.25, 54.33, 54.51, 54.6,
54.79, 54.88, 55.06, 55.21, 55.38, 55.56, 55.65, 55.83, 55.92,
56.1, 56.19, 56.37, 56.46, 56.64, 56.74, 56.91, 57.07, 57.14,
57.27, 57.33, 57.42, 57.45, 57.48, 57.49, 57.48, 57.48, 57.42,
57.31, 57.24, 57.08, 56.99, 56.84, 56.74, 56.54, 56.44, 56.22,
56.05, 55.89, 55.77, 55.54, 55.31, 55.2, 54.99, 54.88, 54.66,
54.55, 54.34, 54.23, 54.03, 53.84, 53.68, 53.49, 53.4, 53.22,
53.14, 52.97, 52.88, 52.72, 52.63, 52.46, 52.38, 52.2, 52.02,
51.93, 51.76, 51.68, 51.51, 51.43, 51.23, 51.15, 50.99, 50.94,
50.79, 50.72, 50.55, 50.46, 50.29, 50.21, 50.06, 49.91, 49.84,
49.68, 49.6, 49.44, 49.36, 49.2, 49.13, 48.98, 48.91, 48.77,
48.7, 48.56, 48.49, 48.35, 48.28, 48.14, 48.07, 47.94, 47.83,
47.7, 47.64, 47.56, 47.51, 47.39, 47.25, 47.2, 47.09, 47.04,
46.98, 46.94, 46.86, 46.82, 46.76, 46.72, 46.63, 46.6, 46.54,
46.51, 46.48, 46.44, 46.39, 46.37, 46.34, 46.33, 46.3, 46.3,
46.29, 46.28, 46.25, 46.24, 46.22, 46.2, 46.2, 46.2, 46.2, 46.19,
46.19, 46.19, 46.18, 46.16, 46.16, 46.14, 46.13, 46.11, 46.1,
46.09, 46.08, 46.06, 46.06, 46.05, 46.04, 46.02, 46, 45.98, 45.95,
45.94, 45.9, 45.88, 45.85, 45.84, 45.81, 45.78, 45.73, 45.71,
45.67, 45.66, 45.62, 45.59, 45.55, 45.54, 45.53, 45.52, 45.48,
45.44, 45.37, 45.34, 45.29, 45.26, 45.2, 45.15, 45.12, 45.06,
45.03, 44.98, 44.96, 44.9, 44.87, 44.8, 44.77, 44.71, 44.68,
44.61, 44.58, 44.53, 44.5, 44.44, 44.41, 44.37, 44.35, 44.3,
44.28, 44.24, 44.22, 44.14, 44.11, 44.05, 44.02, 43.98, 43.96,
43.89, 43.86, 43.8, 43.78, 43.76, 43.75, 43.7, 43.67, 43.63,
43.6, 43.54, 43.5, 43.41, 43.36, 43.3, 43.26, 43.19, 43.16, 43.12,
43.1, 43.08, 43.07, 43.04, 43.02, 42.97, 42.92, 42.88, 42.87,
42.82, 42.81, 42.78, 42.77, 42.74, 42.74, 42.72, 42.69, 42.68,
42.63, 42.6, 42.54, 42.51, 42.46, 42.43, 42.37, 42.35, 42.32,
42.3, 42.25, 42.24, 42.2, 42.18, 42.14, 42.13, 42.07, 42.05,
42, 41.97, 41.93, 41.9, 41.86, 41.83, 41.8, 41.79, 41.76, 41.75,
41.73, 41.72, 41.69, 41.67, 41.61, 41.58, 41.53, 41.5, 41.46,
41.43, 41.39, 41.37, 41.32, 41.3, 41.26, 41.24, 41.19, 41.17,
41.1, 41.07, 41.01, 40.99, 40.94, 40.92, 40.87, 40.84, 40.78,
40.76, 40.74, 40.73, 40.7, 40.68, 40.64, 40.62, 40.57, 40.56,
40.53, 40.53, 40.51, 40.5, 40.48, 40.47, 40.45, 40.44, 40.42,
40.41, 40.41, 40.41, 40.4, 40.4, 40.39, 40.38, 40.35, 40.34,
40.32, 40.32, 40.32, 40.32, 40.31, 40.3, 40.28, 40.28, 40.27,
40.27, 40.27, 40.26, 40.25, 40.25, 40.26, 40.26, 40.26, 40.26,
40.23, 40.22, 40.23, 40.23, 40.23, 40.23, 40.23, 40.22, 40.21,
40.22, 40.22, 40.22, 40.22, 40.21, 40.2, 40.2, 40.19, 40.18,
40.17, 40.16, 40.16, 40.15, 40.15, 40.15, 40.13, 40.11, 40.09,
40.08, 40.08, 40.08, 40.08, 40.08, 40.09, 40.08, 40.08, 40.06,
40.05, 40.04, 40.04, 40.04, 40.04, 40.02, 40.02, 40.01, 40.01,
40.01, 39.98, 39.97, 39.93, 39.92, 39.91, 39.91, 39.9, 39.89,
39.88, 39.87, 39.85, 39.86, 39.87, 39.87, 39.86, 39.86, 39.85,
39.85, 39.86, 39.87, 39.87, 39.87, 39.87, 39.87, 39.85, 39.85,
39.84, 39.83, 39.82, 39.81, 39.79, 39.78, 39.75, 39.74, 39.72,
39.71, 39.7, 39.68, 39.66, 39.65, 39.64, 39.63, 39.6, 39.59,
39.57, 39.57, 39.55, 39.54, 39.5, 39.49, 39.48, 39.47, 39.47,
39.47, 39.47, 39.47, 39.47, 39.47, 39.46, 39.46, 39.46, 39.45,
39.44, 39.42, 39.4, 39.38, 39.37, 39.35, 39.34, 39.31, 39.28,
39.26, 39.24, 39.22, 39.2, 39.18, 39.17, 39.16, 39.16, 39.17,
39.17, 39.16, 39.15, 39.14, 39.14, 39.14, 39.14, 39.14, 39.14,
39.14, 39.13, 39.12, 39.12, 39.11, 39.11, 39.1, 39.1, 39.09,
39.09, 39.08, 39.07, 39.07, 39.07, 39.07, 39.07, 39.07, 39.06,
39.05, 39.04, 39.04, 39.03, 39.02, 39, 39, 38.99, 38.99, 38.99,
39, 38.99, 38.99, 38.98, 38.98, 38.98, 38.99, 39, 39.01, 39.02,
39.01, 38.99, 38.98, 38.96, 38.96, 38.96, 38.95, 38.94, 38.93,
38.9, 38.89, 38.87, 38.86, 38.84, 38.84, 38.85, 38.85, 38.83,
38.83, 38.83, 38.83, 38.83, 38.83, 38.82, 38.81, 38.81, 38.8,
38.78, 38.78, 38.77, 38.77, 38.76, 38.74, 38.73, 38.73, 38.73,
38.72, 38.72, 38.72, 38.72, 38.7, 38.69, 38.68, 38.68, 38.67,
38.67, 38.65, 38.65, 38.62, 38.61, 38.6, 38.6, 38.59, 38.59,
38.59, 38.59, 38.6, 38.59, 38.58, 38.59, 38.59, 38.59, 38.59,
38.59, 38.58, 38.56, 38.55, 38.55, 38.54, 38.53, 38.51, 38.5,
38.49, 38.47, 38.46, 38.44, 38.43, 38.4, 38.39, 38.38, 38.37,
38.35, 38.34, 38.33, 38.32, 38.32, 38.31, 38.29, 38.27, 38.24,
38.23, 38.21, 38.2, 38.17, 38.16, 38.15, 38.14, 38.12, 38.11,
38.09, 38.09, 38.08, 38.08, 38.07, 38.06, 38.04, 38.03, 38.02,
38.01, 38, 37.99, 37.98, 37.97, 37.95, 37.94, 37.93, 37.93, 37.92,
37.92, 37.91, 37.91, 37.9, 37.9, 37.9, 37.9, 37.9, 37.9, 37.9,
37.9, 37.89, 37.89, 37.88, 37.88, 37.88, 37.87, 37.86, 37.85,
37.85, 37.86, 37.87, 37.87, 37.87, 37.88, 37.89, 37.89, 37.89,
37.88, 37.88, 37.88, 37.87, 37.87, 37.87, 37.85, 37.85, 37.84,
37.84, 37.83, 37.83, 37.82, 37.81, 37.81, 37.81, 37.8, 37.8,
37.8, 37.8, 37.8, 37.79, 37.79, 37.78, 37.76, 37.76, 37.75, 37.75,
37.75, 37.75, 37.74, 37.74, 37.74, 37.74, 37.74, 37.74, 37.74,
37.74, 37.74, 37.74, 37.74, 37.74, 37.74, 37.74, 37.73, 37.73,
37.73, 37.73, 37.74, 37.74, 37.74, 37.74, 37.74, 37.73, 37.73,
37.73, 37.73, 37.73, 37.73, 37.71, 37.7, 37.7, 37.7, 37.7, 37.7,
37.71, 37.7, 37.71, 37.7, 37.7, 37.7, 37.7, 37.71, 37.72, 37.72,
37.74, 37.73, 37.72, 37.72, 37.71, 37.7, 37.69, 37.68, 37.68,
37.68, 37.69, 37.69, 37.7, 37.7, 37.7, 37.69, 37.68, 37.67, 37.66,
37.65, 37.65, 37.64, 37.64, 37.62, 37.62, 37.61, 37.6, 37.6,
37.6, 37.58, 37.57, 37.56, 37.55, 37.54, 37.54, 37.55, 37.55,
37.55, 37.54, 37.54, 37.54, 37.53, 37.53, 37.52, 37.52, 37.52,
37.51, 37.51, 37.5, 37.49, 37.48, 37.49, 37.49, 37.5, 37.5, 37.51,
37.52, 37.54, 37.54, 37.54, 37.54, 37.53, 37.52, 37.51, 37.5,
37.51, 37.52, 37.51, 37.51, 37.51, 37.52, 37.53, 37.53, 37.53,
37.52, 37.52, 37.52, 37.52, 37.51, 37.5, 37.5, 37.5, 37.5, 37.5,
37.5, 37.5, 37.5, 37.5, 37.5, 37.5, 37.5, 37.5, 37.49, 37.49,
37.49, 37.49, 37.49, 37.48, 37.49, 37.49, 37.5, 37.5, 37.5, 37.5,
37.49, 37.5, 37.5, 37.5, 37.5, 37.49, 37.49, 37.49, 37.49, 37.49,
37.49, 37.46, 37.45, 37.42, 37.42, 37.39, 37.37, 37.35, 37.34,
37.33, 37.32, 37.31, 37.3, 37.29, 37.29, 37.28, 37.28, 37.27,
37.26, 37.26, 37.26, 37.26, 37.26, 37.26, 37.25, 37.25, 37.24,
37.24, 37.24, 37.24, 37.24, 37.24, 37.23, 37.23, 37.22, 37.21,
37.21, 37.2, 37.19, 37.19, 37.18, 37.17, 37.15, 37.14, 37.12,
37.11, 37.1, 37.1, 37.09, 37.08, 37.08, 37.09, 37.1, 37.11, 37.12,
37.13, 37.14, 37.15, 37.16, 37.16, 37.17, 37.18, 37.18, 37.19,
37.2, 37.21, 37.22, 37.22, 37.22, 37.22, 37.21, 37.21, 37.2,
37.2, 37.18, 37.18, 37.16, 37.15, 37.14, 37.13, 37.12, 37.12,
37.12, 37.12, 37.13, 37.13, 37.12, 37.11, 37.1, 37.08, 37.08,
37.07, 37.07, 37.07, 37.07, 37.08, 37.08, 37.06, 37.05, 37.04,
37.04, 37.04, 37.04, 37.04, 37.04, 37.03, 37.03, 37.02, 37.02,
37.02, 37.01, 37, 37, 36.98, 36.97, 36.95, 36.95, 36.93, 36.93,
36.92, 36.92, 36.91, 36.9, 36.91, 36.91, 36.91, 36.91, 36.91,
36.91, 36.91, 36.91, 36.91, 36.9, 36.89, 36.89, 36.88, 36.88,
36.87, 36.88, 36.89, 36.9, 36.9, 36.9, 36.9, 36.89, 36.88, 36.87,
36.87, 36.88, 36.89, 36.88, 36.88, 36.88, 36.88, 36.88, 36.88,
36.88, 36.88, 36.88, 36.88, 36.89, 36.89, 36.9, 36.91, 36.92,
36.93, 36.93, 36.94, 36.94, 36.95, 36.96, 36.96, 36.96, 36.97,
36.97, 36.97, 36.97, 36.97, 36.97, 36.96, 36.96, 36.97, 36.98,
37, 37, 36.99, 36.99, 36.99, 37, 37, 37, 37, 37, 36.99, 36.99,
36.98, 36.98, 36.98, 36.98, 36.98, 36.98, 36.98, 36.97, 36.96,
36.95, 36.95, 36.95, 36.95, 36.95, 36.95, 36.95, 36.95, 36.93,
36.93, 36.94, 36.94, 36.94, 36.93, 36.91, 36.91, 36.92, 36.93,
36.93, 36.92, 36.91, 36.91, 36.91, 36.91, 36.9, 36.9, 36.9, 36.89,
36.88, 36.86, 36.85, 36.85, 36.84, 36.84, 36.83, 36.82, 36.81,
36.8, 36.8, 36.81, 36.82, 36.83, 36.83, 36.83, 36.83, 36.83,
36.83, 36.83, 36.83, 36.84, 36.84, 36.85, 36.85, 36.85, 36.85,
36.85, 36.85, 36.83, 36.83, 36.81, 36.81, 36.8, 36.8, 36.81,
36.81, 36.81, 36.8, 36.8, 36.79, 36.79, 36.8, 36.79, 36.78, 36.78,
36.78, 36.79, 36.79, 36.79, 36.78, 36.78, 36.8, 36.81, 36.82,
36.82, 36.84, 36.85, 36.85, 36.85, 36.85, 36.85, 36.84, 36.84,
36.83, 36.84, 36.85, 36.84, 36.83, 36.82, 36.8, 36.8, 36.8, 36.8,
36.8, 36.79, 36.78, 36.77, 36.78, 36.78, 36.79, 36.79, 36.79,
36.79, 36.79, 36.78, 36.77, 36.77, 36.78, 36.77, 36.77, 36.76,
36.76, 36.76, 36.76, 36.76, 36.75, 36.75, 36.75, 36.75, 36.75,
36.75, 36.75, 36.74, 36.74, 36.74, 36.73, 36.71, 36.71, 36.71,
36.71, 36.71, 36.71, 36.7, 36.7, 36.69, 36.67, 36.66, 36.66,
36.66, 36.66, 36.66, 36.66, 36.66, 36.65, 36.65, 36.66, 36.66,
36.67, 36.67, 36.66, 36.66, 36.66, 36.67, 36.66, 36.64, 36.62,
36.62, 36.62, 36.62, 36.61, 36.61, 36.6, 36.61, 36.6, 36.61,
36.6, 36.61, 36.61, 36.63, 36.64, 36.64, 36.65, 36.65, 36.65,
36.64, 36.65, 36.66, 36.66, 36.66, 36.66, 36.64, 36.64, 36.63,
36.63, 36.63, 36.63, 36.61, 36.61, 36.61, 36.63, 36.63, 36.64,
36.64, 36.65, 36.65, 36.64, 36.64, 36.63, 36.63, 36.63, 36.62,
36.61, 36.61, 36.6, 36.59, 36.6, 36.6, 36.61, 36.61, 36.62, 36.62,
36.63, 36.64, 36.65, 36.65, 36.66, 36.65, 36.65, 36.64, 36.64,
36.64, 36.64, 36.64, 36.65, 36.66, 36.66, 36.66, 36.65, 36.65,
36.65, 36.66, 36.66, 36.67, 36.67, 36.68, 36.69, 36.7, 36.7,
36.7, 36.69, 36.69, 36.69, 36.69, 36.69, 36.7, 36.71, 36.73,
36.74, 36.74, 36.75, 36.75, 36.76, 36.76, 36.76, 36.78, 36.78,
36.79, 36.79, 36.8, 36.81, 36.82, 36.82, 36.81, 36.8, 36.79,
36.79, 36.79, 36.79, 36.79, 36.79, 36.8, 36.81, 36.81, 36.81,
36.81, 36.81, 36.81, 36.81, 36.82, 36.82, 36.83, 36.83, 36.84,
36.84, 36.83, 36.83, 36.83, 36.83, 36.84, 36.84, 36.83, 36.83,
36.83, 36.84, 36.84, 36.83, 36.83, 36.83, 36.84, 36.85, 36.86,
36.88, 36.88, 36.87, 36.87, 36.88, 36.88, 36.88, 36.88, 36.87,
36.87, 36.87, 36.87, 36.88, 36.88, 36.88, 36.88, 36.87, 36.87,
36.87, 36.84, 36.83, 36.82, 36.82, 36.81, 36.81, 36.81, 36.81,
36.82, 36.81, 36.81, 36.8, 36.79, 36.79, 36.8, 36.8, 36.8, 36.8,
36.81, 36.82, 36.84, 36.84, 36.84, 36.84, 36.84, 36.85, 36.85,
36.85, 36.84, 36.82, 36.81, 36.8, 36.79, 36.79, 36.8, 36.78,
36.78, 36.78, 36.79, 36.78, 36.78, 36.78, 36.78, 36.77, 36.77,
36.78, 36.79, 36.81, 36.81, 36.81, 36.81, 36.81, 36.82, 36.82,
36.82, 36.82, 36.82, 36.81, 36.8, 36.79, 36.79, 36.79, 36.79,
36.79, 36.77, 36.76, 36.76, 36.75, 36.74, 36.74, 36.72, 36.72,
36.71, 36.71, 36.72, 36.72, 36.71, 36.71, 36.71, 36.71, 36.71,
36.72, 36.72, 36.72, 36.71, 36.71, 36.72, 36.71, 36.7, 36.69,
36.68, 36.67, 36.66, 36.65, 36.64, 36.63, 36.63, 36.61, 36.6,
36.58, 36.59, 36.58, 36.59, 36.6, 36.61, 36.61, 36.61, 36.61,
36.61, 36.61, 36.61, 36.6, 36.6, 36.6, 36.6, 36.6, 36.59, 36.6,
36.6, 36.6, 36.6, 36.6, 36.6, 36.58, 36.57, 36.56, 36.54, 36.54,
36.54, 36.54, 36.53, 36.52, 36.51, 36.51, 36.51, 36.51, 36.48,
36.47, 36.47, 36.47, 36.47, 36.47, 36.47, 36.47, 36.47, 36.47,
36.46, 36.46, 36.47, 36.47, 36.46, 36.46, 36.46, 36.45, 36.43,
36.43, 36.42, 36.42, 36.41, 36.4, 36.4, 36.39, 36.39, 36.37,
36.37, 36.38, 36.38, 36.38, 36.37, 36.35, 36.34, 36.34, 36.34,
36.34, 36.34, 36.35, 36.36, 36.36, 36.36, 36.37, 36.36, 36.36,
36.35), Time = c(0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18,
0.2, 0.22, 0.24, 0.26, 0.28, 0.3, 0.32, 0.34, 0.36, 0.38, 0.4,
0.42, 0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56, 0.58, 0.6, 0.62,
0.64, 0.66, 0.68, 0.7, 0.72, 0.74, 0.76, 0.78, 0.8, 0.82, 0.84,
0.86, 0.88, 0.9, 0.92, 0.94, 0.96, 0.98, 1, 1.02, 1.04, 1.06,
1.08, 1.1, 1.12, 1.14, 1.16, 1.18, 1.2, 1.22, 1.24, 1.26, 1.28,
1.3, 1.32, 1.34, 1.36, 1.38, 1.4, 1.42, 1.44, 1.46, 1.48, 1.5,
1.52, 1.54, 1.56, 1.58, 1.6, 1.62, 1.64, 1.66, 1.68, 1.7, 1.72,
1.74, 1.76, 1.78, 1.8, 1.82, 1.84, 1.86, 1.88, 1.9, 1.92, 1.94,
1.96, 1.98, 2, 2.02, 2.04, 2.06, 2.08, 2.1, 2.12, 2.14, 2.16,
2.18, 2.2, 2.22, 2.24, 2.26, 2.28, 2.3, 2.32, 2.34, 2.36, 2.38,
2.4, 2.42, 2.44, 2.46, 2.48, 2.5, 2.52, 2.54, 2.56, 2.58, 2.6,
2.62, 2.64, 2.66, 2.68, 2.7, 2.72, 2.74, 2.76, 2.78, 2.8, 2.82,
2.84, 2.86, 2.88, 2.9, 2.92, 2.94, 2.96, 2.98, 3, 3.02, 3.04,
3.06, 3.08, 3.1, 3.12, 3.14, 3.16, 3.18, 3.2, 3.22, 3.24, 3.26,
3.28, 3.3, 3.32, 3.34, 3.36, 3.38, 3.4, 3.42, 3.44, 3.46, 3.48,
3.5, 3.52, 3.54, 3.56, 3.58, 3.6, 3.62, 3.64, 3.66, 3.68, 3.7,
3.72, 3.74, 3.76, 3.78, 3.8, 3.82, 3.84, 3.86, 3.88, 3.9, 3.92,
3.94, 3.96, 3.98, 4, 4.02, 4.04, 4.06, 4.08, 4.1, 4.12, 4.14,
4.16, 4.18, 4.2, 4.22, 4.24, 4.26, 4.28, 4.3, 4.32, 4.34, 4.36,
4.38, 4.4, 4.42, 4.44, 4.46, 4.48, 4.5, 4.52, 4.54, 4.56, 4.58,
4.6, 4.62, 4.64, 4.66, 4.68, 4.7, 4.72, 4.74, 4.76, 4.78, 4.8,
4.82, 4.84, 4.86, 4.88, 4.9, 4.92, 4.94, 4.96, 4.98, 5, 5.02,
5.04, 5.06, 5.08, 5.1, 5.12, 5.14, 5.16, 5.18, 5.2, 5.22, 5.24,
5.26, 5.28, 5.3, 5.32, 5.34, 5.36, 5.38, 5.4, 5.42, 5.44, 5.46,
5.48, 5.5, 5.52, 5.54, 5.56, 5.58, 5.6, 5.62, 5.64, 5.66, 5.68,
5.7, 5.72, 5.74, 5.76, 5.78, 5.8, 5.82, 5.84, 5.86, 5.88, 5.9,
5.92, 5.94, 5.96, 5.98, 6, 6.02, 6.04, 6.06, 6.08, 6.1, 6.12,
6.14, 6.16, 6.18, 6.2, 6.22, 6.24, 6.26, 6.28, 6.3, 6.32, 6.34,
6.36, 6.38, 6.4, 6.42, 6.44, 6.46, 6.48, 6.5, 6.52, 6.54, 6.56,
6.58, 6.6, 6.62, 6.64, 6.66, 6.68, 6.7, 6.72, 6.74, 6.76, 6.78,
6.8, 6.82, 6.84, 6.86, 6.88, 6.9, 6.92, 6.94, 6.96, 6.98, 7,
7.02, 7.04, 7.06, 7.08, 7.1, 7.12, 7.14, 7.16, 7.18, 7.2, 7.22,
7.24, 7.26, 7.28, 7.3, 7.32, 7.34, 7.36, 7.38, 7.4, 7.42, 7.44,
7.46, 7.48, 7.5, 7.52, 7.54, 7.56, 7.58, 7.6, 7.62, 7.64, 7.66,
7.68, 7.7, 7.72, 7.74, 7.76, 7.78, 7.8, 7.82, 7.84, 7.86, 7.88,
7.9, 7.92, 7.94, 7.96, 7.98, 8, 8.02, 8.04, 8.06, 8.08, 8.1,
8.12, 8.14, 8.16, 8.18, 8.2, 8.22, 8.24, 8.26, 8.28, 8.3, 8.32,
8.34, 8.36, 8.38, 8.4, 8.42, 8.44, 8.46, 8.48, 8.5, 8.52, 8.54,
8.56, 8.58, 8.6, 8.62, 8.64, 8.66, 8.68, 8.7, 8.72, 8.74, 8.76,
8.78, 8.8, 8.82, 8.84, 8.86, 8.88, 8.9, 8.92, 8.94, 8.96, 8.98,
9, 9.02, 9.04, 9.06, 9.08, 9.1, 9.12, 9.14, 9.16, 9.18, 9.2,
9.22, 9.24, 9.26, 9.28, 9.3, 9.32, 9.34, 9.36, 9.38, 9.4, 9.42,
9.44, 9.46, 9.48, 9.5, 9.52, 9.54, 9.56, 9.58, 9.6, 9.62, 9.64,
9.66, 9.68, 9.7, 9.72, 9.74, 9.76, 9.78, 9.8, 9.82, 9.84, 9.86,
9.88, 9.9, 9.92, 9.94, 9.96, 9.98, 10, 10.02, 10.04, 10.06, 10.08,
10.1, 10.12, 10.14, 10.16, 10.18, 10.2, 10.22, 10.24, 10.26,
10.28, 10.3, 10.32, 10.34, 10.36, 10.38, 10.4, 10.42, 10.44,
10.46, 10.48, 10.5, 10.52, 10.54, 10.56, 10.58, 10.6, 10.62,
10.64, 10.66, 10.68, 10.7, 10.72, 10.74, 10.76, 10.78, 10.8,
10.82, 10.84, 10.86, 10.88, 10.9, 10.92, 10.94, 10.96, 10.98,
11, 11.02, 11.04, 11.06, 11.08, 11.1, 11.12, 11.14, 11.16, 11.18,
11.2, 11.22, 11.24, 11.26, 11.28, 11.3, 11.32, 11.34, 11.36,
11.38, 11.4, 11.42, 11.44, 11.46, 11.48, 11.5, 11.52, 11.54,
11.56, 11.58, 11.6, 11.62, 11.64, 11.66, 11.68, 11.7, 11.72,
11.74, 11.76, 11.78, 11.8, 11.82, 11.84, 11.86, 11.88, 11.9,
11.92, 11.94, 11.96, 11.98, 12, 12.02, 12.04, 12.06, 12.08, 12.1,
12.12, 12.14, 12.16, 12.18, 12.2, 12.22, 12.24, 12.26, 12.28,
12.3, 12.32, 12.34, 12.36, 12.38, 12.4, 12.42, 12.44, 12.46,
12.48, 12.5, 12.52, 12.54, 12.56, 12.58, 12.6, 12.62, 12.64,
12.66, 12.68, 12.7, 12.72, 12.74, 12.76, 12.78, 12.8, 12.82,
12.84, 12.86, 12.88, 12.9, 12.92, 12.94, 12.96, 12.98, 13, 13.02,
13.04, 13.06, 13.08, 13.1, 13.12, 13.14, 13.16, 13.18, 13.2,
13.22, 13.24, 13.26, 13.28, 13.3, 13.32, 13.34, 13.36, 13.38,
13.4, 13.42, 13.44, 13.46, 13.48, 13.5, 13.52, 13.54, 13.56,
13.58, 13.6, 13.62, 13.64, 13.66, 13.68, 13.7, 13.72, 13.74,
13.76, 13.78, 13.8, 13.82, 13.84, 13.86, 13.88, 13.9, 13.92,
13.94, 13.96, 13.98, 14, 14.02, 14.04, 14.06, 14.08, 14.1, 14.12,
14.14, 14.16, 14.18, 14.2, 14.22, 14.24, 14.26, 14.28, 14.3,
14.32, 14.34, 14.36, 14.38, 14.4, 14.42, 14.44, 14.46, 14.48,
14.5, 14.52, 14.54, 14.56, 14.58, 14.6, 14.62, 14.64, 14.66,
14.68, 14.7, 14.72, 14.74, 14.76, 14.78, 14.8, 14.82, 14.84,
14.86, 14.88, 14.9, 14.92, 14.94, 14.96, 14.98, 15, 15.02, 15.04,
15.06, 15.08, 15.1, 15.12, 15.14, 15.16, 15.18, 15.2, 15.22,
15.24, 15.26, 15.28, 15.3, 15.32, 15.34, 15.36, 15.38, 15.4,
15.42, 15.44, 15.46, 15.48, 15.5, 15.52, 15.54, 15.56, 15.58,
15.6, 15.62, 15.64, 15.66, 15.68, 15.7, 15.72, 15.74, 15.76,
15.78, 15.8, 15.82, 15.84, 15.86, 15.88, 15.9, 15.92, 15.94,
15.96, 15.98, 16, 16.02, 16.04, 16.06, 16.08, 16.1, 16.12, 16.14,
16.16, 16.18, 16.2, 16.22, 16.24, 16.26, 16.28, 16.3, 16.32,
16.34, 16.36, 16.38, 16.4, 16.42, 16.44, 16.46, 16.48, 16.5,
16.52, 16.54, 16.56, 16.58, 16.6, 16.62, 16.64, 16.66, 16.68,
16.7, 16.72, 16.74, 16.76, 16.78, 16.8, 16.82, 16.84, 16.86,
16.88, 16.9, 16.92, 16.94, 16.96, 16.98, 17, 17.02, 17.04, 17.06,
17.08, 17.1, 17.12, 17.14, 17.16, 17.18, 17.2, 17.22, 17.24,
17.26, 17.28, 17.3, 17.32, 17.34, 17.36, 17.38, 17.4, 17.42,
17.44, 17.46, 17.48, 17.5, 17.52, 17.54, 17.56, 17.58, 17.6,
17.62, 17.64, 17.66, 17.68, 17.7, 17.72, 17.74, 17.76, 17.78,
17.8, 17.82, 17.84, 17.86, 17.88, 17.9, 17.92, 17.94, 17.96,
17.98, 18, 18.02, 18.04, 18.06, 18.08, 18.1, 18.12, 18.14, 18.16,
18.18, 18.2, 18.22, 18.24, 18.26, 18.28, 18.3, 18.32, 18.34,
18.36, 18.38, 18.4, 18.42, 18.44, 18.46, 18.48, 18.5, 18.52,
18.54, 18.56, 18.58, 18.6, 18.62, 18.64, 18.66, 18.68, 18.7,
18.72, 18.74, 18.76, 18.78, 18.8, 18.82, 18.84, 18.86, 18.88,
18.9, 18.92, 18.94, 18.96, 18.98, 19, 19.02, 19.04, 19.06, 19.08,
19.1, 19.12, 19.14, 19.16, 19.18, 19.2, 19.22, 19.24, 19.26,
19.28, 19.3, 19.32, 19.34, 19.36, 19.38, 19.4, 19.42, 19.44,
19.46, 19.48, 19.5, 19.52, 19.54, 19.56, 19.58, 19.6, 19.62,
19.64, 19.66, 19.68, 19.7, 19.72, 19.74, 19.76, 19.78, 19.8,
19.82, 19.84, 19.86, 19.88, 19.9, 19.92, 19.94, 19.96, 19.98,
20, 20.02, 20.04, 20.06, 20.08, 20.1, 20.12, 20.14, 20.16, 20.18,
20.2, 20.22, 20.24, 20.26, 20.28, 20.3, 20.32, 20.34, 20.36,
20.38, 20.4, 20.42, 20.44, 20.46, 20.48, 20.5, 20.52, 20.54,
20.56, 20.58, 20.6, 20.62, 20.64, 20.66, 20.68, 20.7, 20.72,
20.74, 20.76, 20.78, 20.8, 20.82, 20.84, 20.86, 20.88, 20.9,
20.92, 20.94, 20.96, 20.98, 21, 21.02, 21.04, 21.06, 21.08, 21.1,
21.12, 21.14, 21.16, 21.18, 21.2, 21.22, 21.24, 21.26, 21.28,
21.3, 21.32, 21.34, 21.36, 21.38, 21.4, 21.42, 21.44, 21.46,
21.48, 21.5, 21.52, 21.54, 21.56, 21.58, 21.6, 21.62, 21.64,
21.66, 21.68, 21.7, 21.72, 21.74, 21.76, 21.78, 21.8, 21.82,
21.84, 21.86, 21.88, 21.9, 21.92, 21.94, 21.96, 21.98, 22, 22.02,
22.04, 22.06, 22.08, 22.1, 22.12, 22.14, 22.16, 22.18, 22.2,
22.22, 22.24, 22.26, 22.28, 22.3, 22.32, 22.34, 22.36, 22.38,
22.4, 22.42, 22.44, 22.46, 22.48, 22.5, 22.52, 22.54, 22.56,
22.58, 22.6, 22.62, 22.64, 22.66, 22.68, 22.7, 22.72, 22.74,
22.76, 22.78, 22.8, 22.82, 22.84, 22.86, 22.88, 22.9, 22.92,
22.94, 22.96, 22.98, 23, 23.02, 23.04, 23.06, 23.08, 23.1, 23.12,
23.14, 23.16, 23.18, 23.2, 23.22, 23.24, 23.26, 23.28, 23.3,
23.32, 23.34, 23.36, 23.38, 23.4, 23.42, 23.44, 23.46, 23.48,
23.5, 23.52, 23.54, 23.56, 23.58, 23.6, 23.62, 23.64, 23.66,
23.68, 23.7, 23.72, 23.74, 23.76, 23.78, 23.8, 23.82, 23.84,
23.86, 23.88, 23.9, 23.92, 23.94, 23.96, 23.98, 24, 24.02, 24.04,
24.06, 24.08, 24.1, 24.12, 24.14, 24.16, 24.18, 24.2, 24.22,
24.24, 24.26, 24.28, 24.3, 24.32, 24.34, 24.36, 24.38, 24.4,
24.42, 24.44, 24.46, 24.48, 24.5, 24.52, 24.54, 24.56, 24.58,
24.6, 24.62, 24.64, 24.66, 24.68, 24.7, 24.72, 24.74, 24.76,
24.78, 24.8, 24.82, 24.84, 24.86, 24.88, 24.9, 24.92, 24.94,
24.96, 24.98, 25, 25.02, 25.04, 25.06, 25.08, 25.1, 25.12, 25.14,
25.16, 25.18, 25.2, 25.22, 25.24, 25.26, 25.28, 25.3, 25.32,
25.34, 25.36, 25.38, 25.4, 25.42, 25.44, 25.46, 25.48, 25.5,
25.52, 25.54, 25.56, 25.58, 25.6, 25.62, 25.64, 25.66, 25.68,
25.7, 25.72, 25.74, 25.76, 25.78, 25.8, 25.82, 25.84, 25.86,
25.88, 25.9, 25.92, 25.94, 25.96, 25.98, 26, 26.02, 26.04, 26.06,
26.08, 26.1, 26.12, 26.14, 26.16, 26.18, 26.2, 26.22, 26.24,
26.26, 26.28, 26.3, 26.32, 26.34, 26.36, 26.38, 26.4, 26.42,
26.44, 26.46, 26.48, 26.5, 26.52, 26.54, 26.56, 26.58, 26.6,
26.62, 26.64, 26.66, 26.68, 26.7, 26.72, 26.74, 26.76, 26.78,
26.8, 26.82, 26.84, 26.86, 26.88, 26.9, 26.92, 26.94, 26.96,
26.98, 27, 27.02, 27.04, 27.06, 27.08, 27.1, 27.12, 27.14, 27.16,
27.18, 27.2, 27.22, 27.24, 27.26, 27.28, 27.3, 27.32, 27.34,
27.36, 27.38, 27.4, 27.42, 27.44, 27.46, 27.48, 27.5, 27.52,
27.54, 27.56, 27.58, 27.6, 27.62, 27.64, 27.66, 27.68, 27.7,
27.72, 27.74, 27.76, 27.78, 27.8, 27.82, 27.84, 27.86, 27.88,
27.9, 27.92, 27.94, 27.96, 27.98, 28, 28.02, 28.04, 28.06, 28.08,
28.1, 28.12, 28.14, 28.16, 28.18, 28.2, 28.22, 28.24, 28.26,
28.28, 28.3, 28.32, 28.34, 28.36, 28.38, 28.4, 28.42, 28.44,
28.46, 28.48, 28.5, 28.52, 28.54, 28.56, 28.58, 28.6, 28.62,
28.64, 28.66, 28.68, 28.7, 28.72, 28.74, 28.76, 28.78, 28.8,
28.82, 28.84, 28.86, 28.88, 28.9, 28.92, 28.94, 28.96, 28.98,
29, 29.02, 29.04, 29.06, 29.08, 29.1, 29.12, 29.14, 29.16, 29.18,
29.2, 29.22, 29.24, 29.26, 29.28, 29.3, 29.32, 29.34, 29.36,
29.38, 29.4, 29.42, 29.44, 29.46, 29.48, 29.5, 29.52, 29.54,
29.56, 29.58, 29.6, 29.62, 29.64, 29.66, 29.68, 29.7, 29.72,
29.74, 29.76, 29.78, 29.8, 29.82, 29.84, 29.86, 29.88, 29.9,
29.92, 29.94, 29.96, 29.98, 30, 30.02, 30.04, 30.06, 30.08, 30.1,
30.12, 30.14, 30.16, 30.18, 30.2, 30.22, 30.24, 30.26, 30.28,
30.3, 30.32, 30.34, 30.36, 30.38, 30.4, 30.42, 30.44, 30.46,
30.48, 30.5, 30.52, 30.54, 30.56, 30.58, 30.6, 30.62, 30.64,
30.66, 30.68, 30.7, 30.72, 30.74, 30.76, 30.78, 30.8, 30.82,
30.84, 30.86, 30.88, 30.9, 30.92, 30.94, 30.96, 30.98, 31, 31.02,
31.04, 31.06, 31.08, 31.1, 31.12, 31.14, 31.16, 31.18, 31.2,
31.22, 31.24, 31.26, 31.28, 31.3, 31.32, 31.34, 31.36, 31.38,
31.4, 31.42, 31.44, 31.46, 31.48, 31.5, 31.52, 31.54, 31.56,
31.58, 31.6, 31.62, 31.64, 31.66, 31.68, 31.7, 31.72, 31.74,
31.76, 31.78, 31.8, 31.82, 31.84, 31.86, 31.88, 31.9, 31.92,
31.94, 31.96, 31.98, 32, 32.02, 32.04, 32.06, 32.08, 32.1, 32.12,
32.14, 32.16, 32.18, 32.2, 32.22, 32.24, 32.26, 32.28, 32.3,
32.32, 32.34, 32.36, 32.38, 32.4, 32.42, 32.44, 32.46, 32.48,
32.5, 32.52, 32.54, 32.56, 32.58, 32.6, 32.62, 32.64, 32.66,
32.68, 32.7, 32.72, 32.74, 32.76, 32.78, 32.8, 32.82, 32.84,
32.86, 32.88, 32.9, 32.92, 32.94, 32.96, 32.98, 33, 33.02, 33.04,
33.06, 33.08, 33.1, 33.12, 33.14, 33.16, 33.18, 33.2, 33.22,
33.24, 33.26, 33.28, 33.3, 33.32, 33.34, 33.36, 33.38, 33.4,
33.42, 33.44, 33.46, 33.48, 33.5, 33.52, 33.54, 33.56, 33.58,
33.6, 33.62, 33.64, 33.66, 33.68, 33.7, 33.72, 33.74, 33.76,
33.78, 33.8, 33.82, 33.84, 33.86, 33.88, 33.9, 33.92, 33.94,
33.96, 33.98, 34, 34.02, 34.04, 34.06, 34.08, 34.1, 34.12, 34.14,
34.16, 34.18, 34.2, 34.22, 34.24, 34.26, 34.28, 34.3, 34.32,
34.34, 34.36, 34.38, 34.4, 34.42, 34.44, 34.46, 34.48, 34.5,
34.52, 34.54, 34.56, 34.58, 34.6, 34.62, 34.64, 34.66, 34.68,
34.7, 34.72, 34.74, 34.76, 34.78, 34.8, 34.82, 34.84, 34.86,
34.88, 34.9, 34.92, 34.94, 34.96, 34.98, 35, 35.02, 35.04, 35.06,
35.08, 35.1, 35.12, 35.14, 35.16, 35.18, 35.2, 35.22, 35.24,
35.26, 35.28, 35.3, 35.32, 35.34, 35.36, 35.38, 35.4, 35.42,
35.44, 35.46, 35.48, 35.5, 35.52, 35.54, 35.56, 35.58, 35.6,
35.62, 35.64, 35.66, 35.68, 35.7, 35.72, 35.74, 35.76, 35.78,
35.8, 35.82, 35.84, 35.86, 35.88, 35.9, 35.92, 35.94, 35.96,
35.98, 36, 36.02, 36.04, 36.06, 36.08, 36.1, 36.12, 36.14, 36.16,
36.18, 36.2, 36.22, 36.24, 36.26, 36.28, 36.3, 36.32, 36.34,
36.36, 36.38, 36.4, 36.42, 36.44, 36.46, 36.48, 36.5, 36.52,
36.54, 36.56, 36.58, 36.6, 36.62, 36.64, 36.66, 36.68, 36.7,
36.72, 36.74, 36.76, 36.78, 36.8, 36.82, 36.84, 36.86, 36.88,
36.9, 36.92, 36.94, 36.96, 36.98, 37, 37.02, 37.04, 37.06, 37.08,
37.1, 37.12, 37.14, 37.16, 37.18, 37.2, 37.22, 37.24, 37.26,
37.28, 37.3, 37.32, 37.34, 37.36, 37.38, 37.4, 37.42, 37.44,
37.46, 37.48, 37.5, 37.52, 37.54, 37.56, 37.58, 37.6, 37.62,
37.64, 37.66, 37.68, 37.7, 37.72, 37.74, 37.76, 37.78, 37.8,
37.82, 37.84, 37.86, 37.88, 37.9, 37.92, 37.94, 37.96, 37.98,
38, 38.02, 38.04, 38.06, 38.08, 38.1, 38.12, 38.14, 38.16, 38.18,
38.2, 38.22, 38.24, 38.26, 38.28, 38.3, 38.32, 38.34, 38.36,
38.38, 38.4, 38.42, 38.44, 38.46, 38.48, 38.5, 38.52, 38.54,
38.56, 38.58, 38.6, 38.62, 38.64, 38.66, 38.68, 38.7, 38.72,
38.74, 38.76, 38.78, 38.8, 38.82, 38.84, 38.86, 38.88, 38.9,
38.92, 38.94, 38.96, 38.98, 39, 39.02, 39.04, 39.06, 39.08, 39.1,
39.12, 39.14, 39.16, 39.18, 39.2, 39.22, 39.24, 39.26, 39.28,
39.3, 39.32, 39.34, 39.36, 39.38, 39.4, 39.42, 39.44, 39.46,
39.48, 39.5, 39.52, 39.54)), row.names = 2:1977, class = "data.frame")
Initially, I was subsetting my data by visually looking at where the peaks are on the graph and then finding the maximum value within each subset.
#Find 1st peak value
dat_peak1 <- subset(dat, Time > 3.5 & Time < 5.6)
dat_peak1_max <- max(dat_peak1$Temp)
[1] 49.91
#Find 2nd peak value
dat_peak2 <- subset(dat, Time > 5.6 & Time < 7.6)
dat_peak2_max <- max(dat_peak2$Temp)
[1] 57.83
#Find 3rd peak value
dat_peak3 <- subset(dat, Time > 7.6 & Time < 9.6)
dat_peak3_max <- max(dat_peak3$Temp)
[1] 57.49
I plotted the determined peak values to determine if they are indeed the peak values.
graph_peak<-ggplot(dat, height = 50) +
geom_line(mapping = aes(x = Time, y = Temp),size=1)+
geom_hline(yintercept = dat_peak1_max, color = "red")+
geom_hline(yintercept = dat_peak2_max, color = "red")+
geom_hline(yintercept = dat_peak3_max, color = "red")+
xlim(0,10) #changed x-axis limits to better see the peaks
graph_peak
Now, for 3 peaks this seems to do the job but sometimes I need to analyze datasets that have more than 3 peaks. That's why I started looking into functions that can determine the peaks of my data. I have tried turnpoints as well as quantmod::findPeaks but that didn't seem to work that well for me as I prefer to get the actual values as an output instead of indices. And also, I'm getting multiple indices instead of just three. With that, I am posting this question solely to figure out how to make pracma::findpeaks work for my application. The biggest struggle for me is the weak documentation that does not help me tweak my code in order to get the peak values that I need to get. Below you will see my various attempts in getting the said peak values.
Attempt 2 - specify # of desired peaks which in this case is 3:
peak_val2 <- findpeaks(dat$Temp, npeaks = 3)
peak_val2
[,1]
[1,] 36.38
[2,] 36.34
[3,] 36.28
Attempt 3 - include sortstr to return peak values in decreasing order:
peak_val3 <- findpeaks(dat$Temp, npeaks = 3, sortstr = TRUE)
peak_val3
Attempt 3 results:
This is interesting because telling the code to change the order gives us completely different outputs as compared to Attempt 2. The first row gave us a correct peak value but rows 2 and 3 are incorrect.
[,1] [,2] [,3] [,4]
[1,] 57.49 430 388 431
[2,] 52.45 387 384 388
[3,] 40.09 785 784 786

Plot anomalies stripes line

Hi how can I make this kind of plot for anomalies? Is there ggplot function ?
The geom_tile function does the trick:
library(RColorBrewer)
col_strip <- brewer.pal(11, "RdBu")
library(ggplot2)
ggplot(df,
aes(x = date, y = 1, fill = Temp))+
geom_tile() +
scale_fill_gradientn(colors = rev(col_strip)) +
guides(fill = guide_colorbar(barwidth = 1)) +
theme_void()
Data:
structure(list(date = structure(c(-32872, -32506, -32141, -31776,
-31411, -31045, -30680, -30315, -29950, -29584, -29219, -28854,
-28489, -28123, -27758, -27393, -27028, -26662, -26297, -25932,
-25567, -25202, -24837, -24472, -24107, -23741, -23376, -23011,
-22646, -22280, -21915, -21550, -21185, -20819, -20454, -20089,
-19724, -19358, -18993, -18628, -18263, -17897, -17532, -17167,
-16802, -16436, -16071, -15706, -15341, -14975, -14610, -14245,
-13880, -13514, -13149, -12784, -12419, -12053, -11688, -11323,
-10958, -10592, -10227, -9862, -9497, -9131, -8766, -8401, -8036,
-7670, -7305, -6940, -6575, -6209, -5844, -5479, -5114, -4748,
-4383, -4018, -3653, -3287, -2922, -2557, -2192, -1826, -1461,
-1096, -731, -365, 0, 365, 730, 1096, 1461, 1826, 2191, 2557,
2922, 3287, 3652, 4018, 4383, 4748, 5113, 5479, 5844, 6209, 6574,
6940, 7305, 7670, 8035, 8401, 8766, 9131, 9496, 9862, 10227,
10592, 10957, 11323, 11688, 12053, 12418, 12784, 13149, 13514,
13879, 14245, 14610, 14975, 15340, 15706, 16071, 16436, 16801,
17167, 17532), class = "Date"), Temp = c(15.16, 16.27, 15.17,
14.83, 15.26, 14.89, 15.26, 15.68, 14.99, 14.7, 14.99, 15.02,
15.74, 16.28, 15.2, 16.11, 15.75, 16.31, 16.04, 16.88, 15.85,
15.36, 15.18, 15.75, 15.68, 15.49, 15.82, 15.44, 15.92, 15.67,
15.64, 15.43, 15.61, 15.57, 15.54, 15.77, 15.81, 15.55, 15.64,
16.28, 16.03, 16.11, 15.91, 15.87, 15.55, 15.55, 17.01, 15.9,
15.74, 15.93, 15.9, 15.66, 15.02, 15.63, 14.53, 15.05, 15.25,
15.62, 15.8, 15.46, 16.02, 15.68, 15.58, 16.45, 16.1, 16.44,
15.82, 16.3, 16.68, 17, 16.11, 16.02, 16.41, 16.79, 16.25, 17.17,
15.78, 16.18, 16.31, 16.53, 16.78, NA, 16.13, 15.64, 16.4, 15.73,
16.44, 15.76, NA, NA, 16.33, 15.53, 15.32, 16.24, 15.98, 16.12,
15.95, 16.13, 16.41, 16.22, 16.65, 16.7, 16.74, 16.48, 16.12,
16.62, 16.38, 16.98, 16.7, 17.06, 17.3, 16.56, 16.39, 15.9, 16.62,
17.7, 16.61, 17.62, 17.12, 16.5, 16.77, 16.99, 16.6, 17.36, 17,
16.86, 17.48, 16.8, 16.8, 17.26, 17.09, 17.48, 16.85, 16.84,
17.16, 17.23, 17.59, 17.95, 17.12)), class = "data.frame", row.names = c(NA,
-139L))

Creating a list of dataframes from one dataframe using dplyr

This is my code:
My dataframe is:
df<-structure(list(BBAS3 = c(22.85, 22.78, 22.8, 22.22, 22.51, 21.11,
20.84, 20.79, 20.67, 20.9, 20.95, 20.7, 21.03, 21.96, 21.9, 21.8,
21.9, 22.49, 22.65, 22.9, 22.19, 22.44, 21.66, 22.5, 22.96, 23.36,
23.64, 23.46, 23.85, 23.74, 23.9, 23.97, 23.95, 23.85, 23.66,
23.52, 23.5, 23.57, 23.28, 23.09, 23.74, 24.09, 23.96, 23.93,
23.07, 23.54, 24.04, 24.82, 24.58, 24.51, 23.88, 23.16, 23.79,
24.61, 25.12, 26, 25.87, 25.44, 25.6, 27.04, 26.8, 27.52, 27.65,
28.36, 28.77, 28.59, 28.63, 28.16, 27.58, 27.49, 27.6, 27.28,
26.95, 27.09, 27.05, 27.29, 26.74, 26.61, 26.04, 26.05, 25.68,
25.8, 25.49, 25.05, 25.33, 25.24, 25.17, 25.16, 25.11, 24.88,
25.44, 24.74, 24.78, 24.97, 25.25, 24.54, 24.64, 24.4, 23.61,
23.24, 23.1, 22.89, 23.29, 23.42, 23.03, 22.57, 22.4, 22.05,
21.88, 22.09, 21.9, 21.47, 21, 20.71, 20.71, 21.13, 20.86, 20.17,
20.46, 20.67, 21.24, 21.29, 21.54, 21.42, 21.06, 20.74, 20.29,
19.56, 19.66, 20.38, 20.93, 21.24, 20.8, 21.05, 20.82, 20.64,
20.73, 20.98, 21.14, 20.89, 20.46, 20.73, 20.56, 20.37, 19.81,
19.27, 19.41, 18.85, 18.73, 18.76, 18.91, 18.63, 19.18, 20.33,
20.31, 19.75, 19.55, 19.5, 19.34, 19.38, 19.41, 20.09, 20.74,
21.09, 21.03, 20.93, 20.5, 21.17, 21.7, 21.49, 22.08, 22.17,
22.7, 23.15, 23.03, 23.45, 24.29, 24.31, 24.2, 24.16, 24.19,
23.8, 24, 23.41, 22.73, 22.29, 22.82, 22.7, 22.96, 22.83, 23,
22.95, 22.01, 22.39, 22.54, 22.7, 22.55, 22.75, 23.25, 23.66,
24.19, 23.99, 24.03, 24.23, 24.93, 25.43, 25.15, 25.61, 25.58,
25.45, 24.92, 24.4, 24.01, 23.88, 24.43, 24.97, 24.96, 24.79,
24.3, 24.07, 23.88, 24.03, 24.21, 24.22, 23.82, 23.47, 23.8,
23.86, 23.77, 24.02, 24.3, 24.39, 23.95, 23.84, 23.59, 23.72,
23.75, 23.33, 23.16, 22.49, 22.5, 22.78, 22.4, 21.52, 21.72,
21.33, 21.61, 21.08, 21.13, 21.09, 20.94, 21.19, 21.31, 21.12,
21.52, 21.61, 21.96, 22.16, 21.88, 22.49, 22.58, 22.71, 22.96,
23.2, 23.74, 23.79, 23.65, 23.85, 23.01, 23.29, 23.65, 23.42,
23.16, 23.03, 23.3, 22.85, 22.67, 22.19, 22.14, 22.32, 22.14,
21.43, 20.35, 19.73, 19.82, 19.98, 20.28, 20.11, 20.11, 19.97,
19.55, 19.63, 19.28, 19.29, 19.15, 19.49, 19.15, 19.15, 19.13,
18.8, 18.28, 18.36, 18.31, 18.28, 18.41, 18.43, 18.07, 18.22,
18.66, 19.53, 20.01, 19.52, 20.08, 18.85, 19.06, 19.04, 18.94,
19.31, 18.94, 19.14, 19.74, 19.74, 19.92, 20.04, 19.83, 20.09,
20.1, 19.52, 19.81, 19.83, 20.44, 21.33, 21.6, 21.83, 21.75,
21.57, 22.44, 22.41, 22.27, 22.98, 23.07, 23.22, 23.01, 22.56,
22.91, 23.05, 22.65, 22.19, 21.71, 21.55, 21.34, 20.82, 20.11,
20.21, 19.93, 20.11, 20.35, 20.69, 20.24, 19.8, 19.87, 20.17,
19.93, 19.99, 20.19, 20.14, 19.8, 19.22, 20.04, 20.68, 20.01,
20.43, 20.14, 20.38, 19.78, 18.89, 18.99, 18.65, 18.82, 18.5,
17.61, 16.47, 16.85, 16.72, 17.04, 17.02, 16.65, 15.57, 15.69,
16.08, 15.93, 15.87, 16.15, 16.63, 17.02, 17.06, 17.06, 16.81,
16.7, 16.05, 16.08, 15.95, 16.34, 17, 17.27, 17.43, 17.5, 16.81,
16.17, 16.01, 16.31, 16.35, 16.35, 16.2, 16.18, 15.85, 16.25,
16.82, 16.86, 16.79, 17.15, 17.37, 17.53, 17.38, 17.29, 18.05,
18.01, 16.98, 16.35, 17.19, 17.3, 17.95, 18.76, 18.77, 18.78,
19.26, 19.22, 19.05, 19, 19.28, 19.82, 19.79, 19.54, 19.36, 19.84,
19.99, 20.26, 20.03, 19.97, 19.65, 20.1, 20.59, 21.16, 20.67,
20.36, 20.24, 20.28, 20.34, 21.62, 21.73)), row.names = c(NA,
-460L), class = c("tbl_df", "tbl", "data.frame"))
I want to create dataframes and put them in a list. The condition to create these dataframes will respect the size of the sample:
I would like to do this with dplyr package.
I did this with a for loop:
samples_size <- c(9,7,5,3)
my_samples <- vector(mode = "list", length(samples_size))
for(i in 1:length(samples_size)){
my_samples[[i]]<-df[1:samples_size[i],]
}
my_samples
How can I do this using dplyr package?
Any help?
Thanks
Using lapply and dplyr
samples_size <- c(9,7,5,3)
list_of_df <- lapply(samples_size,function(i)df %>% sample_n(i))
list_of_df

How to use ggplot2 to plot results from 'segmented' package?

I followed these steps to plot the results of a piecewise linear regression with one breakpoint which I have done by segmented package:
lin.mod <- lm(ChH~CL)
segmented.mod <- segmented(lin.mod, seg.Z=~CL)
data1 <- data.frame(x = CL, y = ChH)
data2 <- data.frame(x = CL, y = broken.line(segmented.mod)$fit)
ggplot(data1, aes(x = CL, y = ChH)) +
geom_point() +
geom_line(data = data2, color = 'blue')
and I get this plot which does not show two lines with a breakpoint!!!
How should I change my codes to get the correct plot?
This is my dataset:
(ChH has 11 missing data)
CL <- c(9.26, 9.38, 9.41, 9.44, 9.52, 9.58, 9.74, 9.91, 10.03, 10.22,
10.23, 10.4, 10.92, 11.15, 11.38, 11.77, 11.79, 12, 12.45, 12.5,
12.54, 12.79, 12.98, 13.04, 13.04, 13.54, 14.26, 14.33, 14.4,
14.56, 14.77, 14.83, 15.14, 15.19, 15.21, 15.46, 15.61, 15.62,
15.82, 15.87, 16.02, 16.04, 16.05, 16.07, 16.26, 16.32, 16.33,
16.41, 16.53, 16.57, 16.63, 16.64, 16.68, 16.76, 16.87, 17.13,
17.2, 17.37, 17.47, 17.49, 17.68, 17.72, 18.04, 18.1, 18.14,
18.16, 18.18, 18.18, 18.18, 18.22, 18.42, 18.55, 18.63, 18.72,
18.75, 18.77, 18.84, 19, 19.03, 19.3, 19.34, 19.35, 19.36, 19.46,
19.58, 19.61, 19.64, 19.7, 19.73, 19.76, 19.85, 19.85, 19.89,
19.93, 19.97, 20.1, 20.13, 20.16, 20.16, 20.22, 20.26, 20.29,
20.31, 20.31, 20.37, 20.43, 20.46, 20.47, 20.61, 20.64, 20.65,
20.66, 20.78, 20.85, 20.85, 20.88, 20.9, 20.98, 21, 21.02, 21.23,
21.26, 21.29, 21.33, 21.39, 21.4, 21.41, 21.45, 21.5, 21.5, 21.58,
21.6, 21.76, 21.85, 21.9, 22.1, 22.12, 22.14, 22.17, 22.2, 22.21,
22.23, 22.24, 22.3, 22.4, 22.42, 22.43, 22.46, 22.47, 22.48,
22.5, 22.68, 22.7, 22.7, 22.75, 22.8, 22.85, 22.89, 22.89, 22.92,
22.93, 22.94, 22.99, 23.19, 23.3, 23.33, 23.42, 23.51, 23.53,
23.67, 23.7, 23.7, 23.72, 23.72, 23.76, 23.77, 23.78, 23.91,
24.05, 24.05, 24.06, 24.08, 24.11, 24.16, 24.17, 24.2, 24.21,
24.3, 24.38, 24.38, 24.43, 24.49, 24.62, 24.89, 24.89, 24.91,
24.92, 24.95, 24.95, 25.07, 25.1, 25.11, 25.13, 25.13, 25.16,
25.28, 25.3, 25.32, 25.42, 25.43, 25.47, 25.6, 25.71, 25.87,
25.92, 25.94, 25.96, 26.14, 26.18, 26.22, 26.32, 26.33, 26.36,
26.43, 26.6, 26.69, 26.73, 26.73, 26.82, 26.83, 26.86, 27, 27,
27.08, 27.09, 27.1, 27.14, 27.23, 27.24, 27.27, 27.3, 27.55,
27.56, 27.81, 27.9, 27.94, 27.94, 27.98, 28.03, 28.03, 28.17,
28.18, 28.2, 28.49, 28.55, 28.7, 28.76, 28.88, 29.07, 29.13,
29.23, 29.43, 29.63, 29.71, 29.75, 29.97, 30.8, 30.87, 31.27,
31.28, 31.33, 31.45, 31.61, 31.64, 31.68, 32.11, 32.91, 33, 33.6,
34.04, 35.04, 36.05, 36.85)
And:
ChH <- c(2.76, 3.03, 2.86, 2.86, 2.99, 3, 2.96, 3.17, 3.12, 3.27, 3.21,
3.08, 3.53, 3.6, 8.7, 3.75, 3.87, 4.17, 4.38, 4.23, 4.04, 4.24,
4.36, 4.2, 8.78, 4.17, 5.02, 5.22, 5.06, 4.9, NA, 5.3, 5.16,
5.51, 4.25, 5.3, 5.25, 5.65, 5.52, 5.57, 5.5, 5.48, 6.14, 4.65,
5.75, 5.41, 5.42, 5.73, 5.63, 5.85, 6.09, 6.05, 5.88, 5.97, 6.64,
5.18, 6.51, 6.38, 6.27, 6.09, 6.62, 6.3, 4.2, 7.13, NA, 5.85,
6.83, 6.75, 6.94, 6.73, 6.23, 6.79, 6.7, 6.87, NA, 6.7, 6.52,
NA, 7.17, 7.06, 7.01, 7.33, 7.04, 6.94, 7.35, 7.01, 7.54, 7.8,
7.75, 7.86, 7.58, 7.09, 7.42, 7.52, 6.69, NA, 7.69, 7.57, 7.34,
7.52, 8.18, 7.51, 7.8, 7.77, 8.07, 7.92, 6.7, 7.43, 7.58, 8.09,
7.7, 7.81, 8.11, 7.83, 7.48, 7.81, 8.27, 8.32, 7.86, 8.1, 8.63,
7.8, 5.42, 8.36, 8.08, NA, 7.78, 8.27, 8.44, 6.62, 8.01, 8.5,
7.86, 9.1, 8.15, 8.69, 8.6, 8.49, 7.98, 8.76, 8.34, 8.75, 7.97,
9.08, 8.29, NA, 8.92, 8.71, 8.94, 8.44, 9, 8.63, 9.15, 8.93,
9.37, 8.77, 9.21, 9.07, 9.1, 8.89, 7.43, 8.34, 8.64, 8.5, 9.59,
7.59, 9.08, 9.4, 9.07, 8.83, 9.46, 9.3, 9.24, 9.44, 9, 9.43,
9.17, 7.68, 9.56, 9.27, 9.33, 6.8, 9.98, 9.81, 9.59, 9.49, 9.55,
9.39, 10.04, 9.5, 9.93, 9.3, 9.49, 8.45, 7.77, 7.84, 9.88, 9.35,
10.09, 10.22, 10.75, 10.75, 8.04, 8.07, 10.14, 9.94, 10.44, 10.25,
9.49, 10.6, 8.41, 9.57, 11.25, NA, 11.61, 6.72, 10.63, 11.12,
10.55, 10.7, 10.18, 10.94, 11.02, 10.66, 10.73, 8.65, 11.84,
NA, 11.25, 11.59, 10.96, 11.58, 11.43, 12.46, 10.46, 10.99, 11.94,
8.77, 11.58, 12.36, 11, 11.05, 11.86, 9.52, 12.48, 12.39, 12.64,
12.28, 12.12, 11.27, 10.86, 12.49, 12.13, 12.74, 9.64, 10.97,
12.41, 12.32, 13.86, 13.04, NA, 10.26, 13.24, 13.89, 12.77, 13.33,
13.37, 13.55, 14.01, 14.25, 14.75, 14.3, 13.87, 14.96, 14.32,
14.49, NA, 15.41, 15.47, 14.31, 17.7, 12.48, 16.46)
Edited to take into account OP's real data
Put everything inside the same data.frame:
library(segmented)
library(ggplot2)
lin.mod <- lm(ChH~CL)
segmented.mod <- segmented(lin.mod, seg.Z=~CL)
fit <- numeric(length(CL)) * NA
fit[complete.cases(rowSums(cbind(ChH, CL)))] <- broken.line(segmented.mod)$fit
data1 <- data.frame(CL = CL, ChH = ChH, fit = fit)
ggplot(data1, aes(x = CL, y = ChH)) +
geom_point() +
geom_line(aes(x = CL, y = fit), color = 'blue')

Resources