Show difference between two matrices as lines through a 3d surface - r
I have a surface that I have represented as a matrix that has observed values. Some of these values are controls, and form a grid throughout my surface. I extracted JUST the controls, and interpolated/extrapolated in between to create a "control surface". Then, I can subtract the control surface from the observed surface to get the normalized values.
(sub)Question 1: The interpolation looks unnecessarily irregular... is my interpolation method correct? If not, is there a better method?
(main)Question 2: How can I visualize the result as lines poking through the control surface with the ids at the top? I would like something like this:
Code follows (sorry for ugly dput):
library(dplyr)
library(tidyr)
library(akima)
b <- structure(list(Entr = 1:931, Row = c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L),
Col = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L,
37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L,
49L, 49L, 48L, 47L, 46L, 45L, 44L, 43L, 42L, 41L, 40L, 39L,
38L, 37L, 36L, 35L, 34L, 33L, 32L, 31L, 30L, 29L, 28L, 27L,
26L, 25L, 24L, 23L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L,
14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L,
1L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L,
49L, 48L, 47L, 46L, 45L, 44L, 43L, 42L, 41L, 40L, 39L, 38L,
37L, 36L, 35L, 34L, 33L, 32L, 31L, 30L, 29L, 28L, 27L, 26L,
25L, 24L, 23L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L,
13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L,
27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L,
39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 49L,
48L, 47L, 46L, 45L, 44L, 43L, 42L, 41L, 40L, 39L, 38L, 37L,
36L, 35L, 34L, 33L, 32L, 31L, 30L, 29L, 28L, 27L, 26L, 25L,
24L, 23L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L,
12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L,
28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L,
40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 49L, 48L,
47L, 46L, 45L, 44L, 43L, 42L, 41L, 40L, 39L, 38L, 37L, 36L,
35L, 34L, 33L, 32L, 31L, 30L, 29L, 28L, 27L, 26L, 25L, 24L,
23L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L,
11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L,
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L,
41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 49L, 48L, 47L,
46L, 45L, 44L, 43L, 42L, 41L, 40L, 39L, 38L, 37L, 36L, 35L,
34L, 33L, 32L, 31L, 30L, 29L, 28L, 27L, 26L, 25L, 24L, 23L,
22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L,
10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L,
30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 49L, 48L, 47L, 46L,
45L, 44L, 43L, 42L, 41L, 40L, 39L, 38L, 37L, 36L, 35L, 34L,
33L, 32L, 31L, 30L, 29L, 28L, 27L, 26L, 25L, 24L, 23L, 22L,
21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L,
9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L,
43L, 44L, 45L, 46L, 47L, 48L, 49L, 49L, 48L, 47L, 46L, 45L,
44L, 43L, 42L, 41L, 40L, 39L, 38L, 37L, 36L, 35L, 34L, 33L,
32L, 31L, 30L, 29L, 28L, 27L, 26L, 25L, 24L, 23L, 22L, 21L,
20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L,
8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L,
32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L,
44L, 45L, 46L, 47L, 48L, 49L, 49L, 48L, 47L, 46L, 45L, 44L,
43L, 42L, 41L, 40L, 39L, 38L, 37L, 36L, 35L, 34L, 33L, 32L,
31L, 30L, 29L, 28L, 27L, 26L, 25L, 24L, 23L, 22L, 21L, 20L,
19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L,
7L, 6L, 5L, 4L, 3L, 2L, 1L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L,
33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L,
45L, 46L, 47L, 48L, 49L, 49L, 48L, 47L, 46L, 45L, 44L, 43L,
42L, 41L, 40L, 39L, 38L, 37L, 36L, 35L, 34L, 33L, 32L, 31L,
30L, 29L, 28L, 27L, 26L, 25L, 24L, 23L, 22L, 21L, 20L, 19L,
18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L,
6L, 5L, 4L, 3L, 2L, 1L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L,
22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L,
46L, 47L, 48L, 49L), Value = c(3597L, 3519L, 2974L, 3499L,
3437L, 3669L, 2972L, 2953L, 3088L, 3224L, 2739L, 2762L, 3238L,
2838L, 2821L, 2765L, 3487L, 3696L, 3708L, 3369L, 3702L, 3362L,
3275L, 3073L, 3313L, 3316L, 3656L, 3898L, 3999L, 4074L, 3768L,
3846L, 3630L, 4130L, 3787L, 3418L, 3053L, 3764L, 3745L, 3187L,
3628L, 3147L, 3441L, 3465L, 3953L, 3288L, 3122L, 2208L, 3008L,
3487L, 3248L, 3411L, 3402L, 3627L, 3232L, 3713L, 3432L, 3657L,
3282L, 3859L, 3464L, 3161L, 3297L, 3308L, 3392L, 3334L, 3187L,
3396L, 3213L, 4019L, 3516L, 3578L, 3670L, 3484L, 3552L, 3365L,
3441L, 4022L, 3881L, 3343L, 3466L, 3128L, 3477L, 3398L, 3761L,
3540L, 3627L, 2864L, 3630L, 3320L, 3849L, 3939L, 3658L, 3424L,
3524L, 3626L, 3177L, 2923L, 3655L, 3750L, 4447L, 4426L, 4891L,
4705L, 4274L, 4398L, 4448L, 4148L, 4210L, 4141L, 4255L, 4083L,
4295L, 3190L, 3939L, 3258L, 3855L, 4181L, 3930L, 3871L, 3977L,
3594L, 4107L, 3416L, 4057L, 3692L, 3967L, 3943L, 4012L, 3852L,
4065L, 4019L, 3687L, 3663L, 4081L, 4015L, 3847L, 3690L, 3994L,
3447L, 3559L, 3636L, 3409L, 3121L, 2958L, 2899L, 3017L, 3158L,
3053L, 3572L, 2975L, 3431L, 3725L, 3702L, 3363L, 3487L, 3562L,
3190L, 3219L, 3923L, 3585L, 3989L, 4005L, 3658L, 3810L, 3983L,
3555L, 3712L, 3699L, 3774L, 3471L, 3428L, 3552L, 3468L, 3099L,
3069L, 3303L, 3470L, 3637L, 3624L, 3813L, 4344L, 3866L, 4044L,
3490L, 3809L, 3428L, 3839L, 2540L, 4349L, 3584L, 3627L, 3799L,
3800L, 2887L, 3523L, 3389L, 3411L, 3193L, 3111L, 3112L, 3222L,
3363L, 3551L, 3430L, 3483L, 3049L, 3340L, 4034L, 3447L, 3865L,
3626L, 3699L, 3758L, 4002L, 3500L, 3650L, 3354L, 3321L, 4088L,
3259L, 3520L, 3444L, 3191L, 3578L, 3369L, 2479L, 4070L, 4171L,
4093L, 4184L, 4295L, 2681L, 3597L, 3901L, 2720L, 2700L, 2717L,
3483L, 3311L, 3223L, 3046L, 3310L, 2531L, 3317L, 3233L, 2134L,
3020L, 3360L, 3679L, 2773L, 3665L, 3124L, 4042L, 3713L, 3862L,
3961L, 4109L, 3794L, 4062L, 4078L, 4181L, 3940L, 4602L, 4149L,
3849L, 3582L, 4035L, 3431L, 3954L, 4244L, 3353L, 3519L, 3496L,
3408L, 2988L, 3327L, 3086L, 3180L, 4583L, 3742L, 4580L, 4707L,
4247L, 4422L, 4426L, 4100L, 4042L, 4096L, 3703L, 4001L, 4002L,
4265L, 3249L, 4765L, 4280L, 4628L, 4905L, 4611L, 4010L, 4125L,
4452L, 5044L, 4932L, 4613L, 4768L, 5033L, 4199L, 3944L, 3951L,
4179L, 4192L, 4195L, 3889L, 3928L, 3301L, 3764L, 3537L, 3843L,
4342L, 3792L, 3973L, 4251L, 4169L, 4374L, 4172L, 4028L, 3050L,
4488L, 4068L, 4697L, 4824L, 4184L, 3930L, 4012L, 3219L, 3519L,
3663L, 3493L, 2939L, 3363L, 3383L, 3464L, 2789L, 2927L, 3059L,
2884L, 2782L, 3090L, 3158L, 3132L, 3644L, 3803L, 3895L, 3885L,
3265L, 3682L, 3464L, 3171L, 3539L, 3474L, 3265L, 3666L, 3549L,
3591L, 3249L, 3173L, 3088L, 2563L, 3530L, 3234L, 3453L, 3200L,
3405L, 3471L, 3750L, 2906L, 3241L, 3186L, 3789L, 3174L, 2977L,
3281L, 3479L, 3241L, 3783L, 3339L, 3503L, 3591L, 3379L, 3392L,
3399L, 3675L, 3624L, 3772L, 3873L, 3477L, 3950L, 3538L, 4347L,
3818L, 4332L, 3727L, 4028L, 3679L, 3737L, 3444L, 3258L, 3535L,
3555L, 3474L, 3447L, 3748L, 3423L, 3577L, 3725L, 3227L, 2903L,
3526L, 3670L, 3256L, 3282L, 3396L, 3719L, 3598L, 3608L, 3259L,
3610L, 3373L, 3432L, 3393L, 3001L, 2867L, 2982L, 3345L, 3311L,
2727L, 3106L, 3108L, 2950L, 2714L, 3520L, 3016L, 2939L, 3435L,
3020L, 3175L, 3805L, 2779L, 3895L, 3308L, 2995L, 3083L, 3080L,
3432L, 3318L, 4486L, 3876L, 3588L, 3742L, 3986L, 3765L, 3758L,
3523L, 3696L, 3040L, 3448L, 2687L, 3282L, 4166L, 4169L, 3742L,
4032L, 3986L, 4306L, 4371L, 4231L, 4260L, 3585L, 4342L, 4188L,
3220L, 3464L, 3536L, 3595L, 4045L, 3937L, 3886L, 4774L, 3696L,
4214L, 4250L, 4543L, 4550L, 4517L, 4691L, 5042L, 3956L, 3953L,
3986L, 4032L, 3643L, 3562L, 3833L, 3803L, 3634L, 3895L, 4299L,
3862L, 3403L, 3272L, 3406L, 3253L, 3233L, 3344L, 3481L, 3363L,
2646L, 3631L, 3869L, 3246L, 3357L, 3696L, 3859L, 4296L, 3438L,
4000L, 3703L, 3960L, 3477L, 4247L, 3791L, 3853L, 3696L, 3835L,
3742L, 3588L, 3276L, 3093L, 3360L, 3207L, 3576L, 3025L, 3305L,
3295L, 3788L, 3963L, 3999L, 3294L, 3931L, 3448L, 2959L, 3304L,
3131L, 2685L, 3314L, 2887L, 3653L, 3141L, 3425L, 3542L, 3282L,
3478L, 3191L, 2639L, 3027L, 3504L, 3578L, 2806L, 4163L, 3735L,
3203L, 3419L, 3588L, 3545L, 3535L, 3333L, 3392L, 3806L, 3587L,
3134L, 2971L, 3069L, 3316L, 4520L, 3562L, 3665L, 3744L, 3207L,
3409L, 3744L, 3181L, 3096L, 3576L, 3572L, 3363L, 3386L, 3318L,
3791L, 3582L, 4032L, 4394L, 4087L, 4248L, 4342L, 4189L, 4656L,
3781L, 4335L, 3504L, 4267L, 4032L, 3824L, 3609L, 4012L, 3992L,
4417L, 4003L, 3846L, 4140L, 3683L, 3302L, 3859L, 4100L, 3847L,
3621L, 4176L, 4359L, 4081L, 3654L, 4062L, 3442L, 3560L, 3780L,
3295L, 3487L, 3409L, 3439L, 2362L, 3364L, 3412L, 3266L, 4051L,
3990L, 4068L, 3971L, 3197L, 3677L, 3765L, 3638L, 3439L, 4004L,
3648L, 3628L, 3475L, 3945L, 4167L, 3942L, 3929L, 4013L, 3906L,
3168L, 3606L, 4012L, 4317L, 4000L, 3781L, 4199L, 3997L, 4576L,
3997L, 4273L, 3891L, 3543L, 3294L, 3911L, 3715L, 4276L, 3660L,
4090L, 3921L, 3595L, 3513L, 3301L, 3470L, 3363L, 3989L, 3307L,
3565L, 3301L, 3738L, 3907L, 3653L, 3819L, 3232L, 3695L, 3435L,
2906L, 3620L, 3686L, 3284L, 4237L, 4100L, 4420L, 3654L, 2503L,
1680L, 3614L, 3314L, 4302L, 3114L, 2840L, 3036L, 1144L, 4153L,
3416L, 4484L, 3159L, 3839L, 3961L, 3373L, 3722L, 3605L, 3116L,
3818L, 3977L, 3527L, 3562L, 3794L, 4162L, 3800L, 3680L, 3578L,
3924L, 3484L, 3204L, 3200L, 3223L, 3536L, 3187L, 3171L, 3057L,
3268L, 3099L, 3517L, 3477L, 3751L, 3174L, 3569L, 3295L, 3229L,
3451L, 3200L, 3530L, 3798L, 3562L, 3484L, 2718L, 3980L, 3746L,
3576L, 3464L, 3302L, 4107L, 3452L, 3315L, 3680L, 3383L, 3462L,
3478L, 3888L, 3634L, 3445L, 3092L, 3445L, 2923L, 3040L, 2623L,
2874L, 3552L, 2336L, 3011L, 2671L, 2029L, 4002L, 3379L, 3779L,
3763L, 3496L, 3454L, 3613L, 3901L, 3727L, 3365L, 3836L, 2750L,
3763L, 3389L, 3542L, 3699L, 3904L, 3836L, 3399L, 3634L, 4162L,
3545L, 4182L, 3506L, 3849L, 3755L, 3770L, 2936L, 3670L, 3758L,
3487L, 3807L, 2868L, 3523L, 3148L, 3774L, 2851L, 2903L, 3181L,
3067L, 2695L, 3389L, 3670L, 2554L, 3494L, 4162L, 3533L, 2780L,
2822L, 2946L, 3324L, 1791L, 3530L, 3872L, 3676L, 3252L, 3395L,
3370L, 2662L, 2567L, 2786L, 2714L, 2479L, 1465L, 2000L, 3663L,
4375L, 3758L, 3742L, 3259L, 2985L, 3784L, 3373L, 2978L, 3487L,
3379L, 2953L, 3478L, 2890L, 2597L, 3001L, 2861L, 3988L, 3455L,
2950L, 3771L, 3550L, 2998L, 2991L, 3219L, 3073L, 3458L, 3585L,
3546L, 3637L, 4198L, 2903L, 3144L, 2825L, 2806L, 3409L, 1846L,
2564L, 3005L, 2675L, 2936L, 2124L, 2900L, 2388L, 2531L, 2916L,
778L, 2812L, 2577L, 2401L, 2868L, 3041L, 2039L, 2408L, 2104L,
3142L, 2610L, 3748L, 3370L, 2754L, 3546L, 2962L, 2453L, 3014L,
2626L, 2864L, 3399L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L)), class = "data.frame", row.names = c(NA,
-931L), .Names = c("Entr", "Row", "Col", "Value"))
## Control every 10
b$Control[b$Entr%%10==0] <- 1
b$Control[is.na(b$Control)] <- 0
## Isolate controls
b$Yield2[b$Control==1] <- b$Value[b$Control==1]
b$Yield2[is.na(b$Yield2)] <- 0
## -------------------- GENERATE MATRIX FOR SURFACE CALCULATION----------------
## ALL DATA
MaxCol <- max(b$Col)
MaxRow <- max(b$Row)
RealSurf <- matrix(b$Value,MaxRow,MaxCol)
## Matrix of just controls, first emptyish
ControlSurf <- matrix(b$Yield2,MaxRow,MaxCol)
## Interpolate empty data...
idx <- which(ControlSurf > 0, arr.ind=TRUE)
RealSurf.nz <- ControlSurf[idx]
## ... into a fullish matrix
InterpolatedControls <- interp.new(idx[,1], idx[,2], RealSurf.nz, xo=1:MaxRow, yo=1:MaxCol, extrap=TRUE)
ControlSurf <- matrix(InterpolatedControls$z,MaxRow,MaxCol)
##################### ???????????? IS THIS EVEN CORRECT??????? ##################
## Plot surfaces
par(mfrow=c(1,2))
persp( z=ControlSurf, theta = 50, phi = 30, expand = 0.1, col = "lightblue")
persp( z=RealSurf, theta = 50, phi = 30, expand = 0.1, col = "red")
## How to make the real surface "poke" through the Control Surface?
Related
How to use transpose function (t) to transpose rows by hours of day (0 to 23)?
I want to transpose hours of day (0 to 23) on each rows of each subjects( i have 21 subjects) I use to create two data frame: test and teste. Then i use two loops to transpose all (0,1,2,3 to 23) of each subject. But my code is so bad that i can't find expect result. test=data.frame(1:24,t(0:23)) teste=data.frame(1:21,t(0:23)) for(i in 1:21){ for(j in 1:24){ test[j,]=t(data_temps_All1[j,]) j=j+1 } teste[i,]= test[j,] i=i+1 } i want to have: first row: 0 ,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 second row: 0 ,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 --- 21 row: 0 ,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 This is my data set: structure(list(hour = c(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 16L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 6L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L)), row.names = c(NA, -504L), class = c("data.table", "data.frame"))
Since you have only one column you could unlist the data convert it into matrix with required dimension and change it to data frame / data.table data.frame(matrix(unlist(df), ncol = 24, byrow = TRUE))
Don't know what is your application, but isn't this the data.frame you wish to have data.frame(1:21, t(0:23)[rep(1, 21), ])
Arranging time stamped data in chronological order
An output table of one of my codes looks like this: > head(act.byHour_corr) hour date activity 1: 0 Activity on 6/20/2018 59 2: 1 Activity on 6/20/2018 74 3: 2 Activity on 6/20/2018 2683 4: 3 Activity on 6/20/2018 4341 5: 4 Activity on 6/20/2018 3676 6: 5 Activity on 6/20/2018 2143 The column hour represents the hours of the day from 0 to 23 and the data in date is chronologically organized. Unfortunately, when the data comes to the point where the next month 7/dd/2018 is reached, date is not chronologically organized anymore: > head(act.byHour_corr[287:293]) hour date activity 1: 22 Activity on 7/1/2018 400 2: 23 Activity on 7/1/2018 201 3: 0 Activity on 7/10/2018 705 4: 1 Activity on 7/10/2018 47 5: 2 Activity on 7/10/2018 605 6: 3 Activity on 7/10/2018 257 You can see that 7/10/2018 and its associated values come after 7/1/2018 instead of that being 7/2/2018. If that helps I can provide my dataset below: > dput(act.byHour_corr) structure(list(hour = c(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L), date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L), class = "factor", .Label = c("Activity on 6/20/2018", "Activity on 6/21/2018", "Activity on 6/22/2018", "Activity on 6/23/2018", "Activity on 6/24/2018", "Activity on 6/25/2018", "Activity on 6/26/2018", "Activity on 6/27/2018", "Activity on 6/28/2018", "Activity on 6/29/2018", "Activity on 6/30/2018", "Activity on 7/1/2018", "Activity on 7/10/2018", "Activity on 7/11/2018", "Activity on 7/12/2018", "Activity on 7/13/2018", "Activity on 7/14/2018", "Activity on 7/15/2018", "Activity on 7/16/2018", "Activity on 7/17/2018", "Activity on 7/18/2018", "Activity on 7/19/2018", "Activity on 7/2/2018", "Activity on 7/20/2018", "Activity on 7/21/2018", "Activity on 7/22/2018", "Activity on 7/23/2018", "Activity on 7/24/2018", "Activity on 7/25/2018", "Activity on 7/26/2018", "Activity on 7/27/2018", "Activity on 7/28/2018", "Activity on 7/29/2018", "Activity on 7/3/2018", "Activity on 7/30/2018", "Activity on 7/31/2018", "Activity on 7/4/2018", "Activity on 7/5/2018", "Activity on 7/6/2018", "Activity on 7/7/2018", "Activity on 7/8/2018", "Activity on 7/9/2018")), activity = c(59L, 74L, 2683L, 4341L, 3676L, 2143L, 3890L, 3887L, 1299L, 1492L, 3449L, 2200L, 1563L, 4346L, 5329L, 3037L, 1462L, 668L, 383L, 483L, 288L, 2765L, 3354L, 1783L, 241L, 301L, 261L, 3683L, 4356L, 3736L, 2810L, 1841L, 3146L, 609L, 2998L, 4059L, 3690L, 3735L, 1343L, 2087L, 894L, 341L, 240L, 2113L, 1684L, 3115L, 2890L, 138L, 21L, 451L, 96L, 2918L, 2279L, 2282L, 4992L, 698L, 427L, 581L, 1248L, 2184L, 1980L, 2364L, 568L, 2477L, 525L, 433L, 974L, 501L, 760L, 67L, 297L, 1198L, 2L, 39L, 42L, 1182L, 1749L, 2144L, 3123L, 1170L, 1641L, 1112L, 1526L, 1199L, 534L, 1481L, 2388L, 2756L, 392L, 112L, 390L, 107L, 709L, 1122L, 1562L, 451L, 8L, 74L, 0L, 158L, 780L, 3118L, 3292L, 2759L, 3121L, 2051L, 2387L, 900L, 627L, 904L, 4283L, 3726L, 1273L, 977L, 326L, 163L, 1915L, 1073L, 1021L, 545L, 36L, 22L, 3L, 55L, 124L, 22L, 4093L, 2867L, 3649L, 2550L, 1590L, 636L, 2571L, 998L, 1066L, 2967L, 1211L, 51L, 1188L, 1413L, 714L, 177L, 132L, 29L, 22L, 43L, 0L, 90L, 1094L, 1655L, 2643L, 2108L, 2249L, 2453L, 2857L, 915L, 437L, 1142L, 2193L, 2993L, 1139L, 1549L, 652L, 580L, 970L, 674L, 211L, 206L, 167L, 63L, 1L, 786L, 617L, 1575L, 2237L, 1302L, 1149L, 2009L, 2234L, 1263L, 1259L, 2017L, 1641L, 2683L, 1184L, 449L, 65L, 956L, 1538L, 1287L, 593L, 362L, 594L, 1172L, 25L, 445L, 921L, 1812L, 2235L, 1153L, 422L, 1084L, 2158L, 1610L, 845L, 1187L, 2528L, 2161L, 976L, 19L, 747L, 570L, 576L, 19L, 304L, 2L, 301L, 7L, 399L, 494L, 723L, 1088L, 771L, 85L, 1338L, 866L, 384L, 1356L, 2862L, 3805L, 2142L, 1655L, 249L, 235L, 3L, 0L, 283L, 981L, 634L, 1370L, 9L, 137L, 33L, 975L, 1690L, 1639L, 985L, 210L, 1266L, 2135L, 2080L, 1704L, 2449L, 3133L, 1055L, 3222L, 1152L, 173L, 858L, 188L, 700L, 330L, 905L, 1232L, 1006L, 5L, 21L, 520L, 1162L, 1771L, 2463L, 1403L, 1353L, 1938L, 2388L, 4133L, 900L, 2660L, 3504L, 3946L, 1956L, 818L, 604L, 937L, 373L, 48L, 400L, 201L, 705L, 47L, 605L, 257L, 1359L, 41L, 1019L, 1426L, 2219L, 1179L, 1624L, 537L, 421L, 1747L, 2941L, 2921L, 1046L, 283L, 476L, 218L, 59L, 389L, 657L, 1293L, 24L, 455L, 6L, 1232L, 2264L, 1152L, 600L, 11L, 980L, 1519L, 2004L, 1933L, 2161L, 1386L, 1883L, 2978L, 1385L, 104L, 1309L, 2L, 364L, 550L, 0L, 1433L, 1634L, 27L, 860L, 1095L, 1102L, 132L, 582L, 710L, 1368L, 2470L, 2944L, 1030L, 1286L, 387L, 2590L, 2449L, 743L, 134L, 274L, 205L, 360L, 627L, 1357L, 591L, 216L, 143L, 70L, 2L, 477L, 42L, 81L, 304L, 2827L, 2437L, 2002L, 688L, 935L, 812L, 404L, 1098L, 1157L, 857L, 466L, 215L, 714L, 269L, 1223L, 8L, 1L, 635L, 6L, 1797L, 1363L, 246L, 704L, 1089L, 943L, 2251L, 813L, 2643L, 1657L, 18L, 1132L, 2884L, 1044L, 149L, 1146L, 68L, 1227L, 1189L, 129L, 1291L, 7L, 9L, 1299L, 389L, 288L, 157L, 0L, 324L, 248L, 915L, 795L, 598L, 733L, 308L, 2760L, 2874L, 1903L, 499L, 73L, 31L, 1146L, 920L, 852L, 2L, 104L, 564L, 16L, 1903L, 675L, 1859L, 720L, 1017L, 4L, 2114L, 2264L, 1152L, 935L, 1691L, 1031L, 2568L, 2035L, 226L, 18L, 1716L, 249L, 717L, 635L, 919L, 1436L, 16L, 17L, 1891L, 1175L, 74L, 435L, 377L, 718L, 619L, 439L, 1373L, 2154L, 2481L, 763L, 2084L, 910L, 641L, 669L, 737L, 793L, 1471L, 12L, 96L, 6L, 13L, 81L, 1227L, 1685L, 260L, 238L, 575L, 930L, 330L, 1139L, 785L, 1110L, 1007L, 1770L, 2824L, 729L, 776L, 602L, 550L, 1432L, 567L, 197L, 107L, 38L, 648L, 264L, 911L, 2239L, 1063L, 9L, 1336L, 1235L, 628L, 1722L, 1028L, 1393L, 44L, 2110L, 1719L, 666L, 127L, 885L, 788L, 1274L, 765L, 1094L, 38L, 876L, 505L, 162L, 775L, 1567L, 896L, 1648L, 995L, 2574L, 1080L, 997L, 1881L, 1375L, 1283L, 2156L, 2384L, 982L, 33L, 20L, 761L, 241L, 696L, 133L, 915L, 514L, 14L, 59L, 1081L, 1266L, 359L, 1055L, 280L, 123L, 2251L, 2302L, 1116L, 2750L, 764L, 1377L, 2776L, 970L, 814L, 10L, 1364L, 1137L, 279L, 10L, 605L, 279L, 596L, 12L, 1443L, 1463L, 1426L, 132L, 924L, 379L, 693L, 137L, 219L, 884L, 194L, 450L, 1204L, 487L, 578L, 445L, 9L, 823L, 2L, 1212L, 12L, 200L, 9L, 152L, 1062L, 1926L, 1156L, 1951L, 1735L, 753L, 570L, 362L, 813L, 756L, 1403L, 308L, 1895L, 325L, 768L, 666L, 33L, 634L, 1294L, 819L, 39L, 579L, 8L, 657L, 438L, 521L, 896L, 2560L, 1383L, 819L, 1293L, 2257L, 476L, 1850L, 759L, 2482L, 1513L, 789L, 78L, 329L, 43L, 50L, 1583L, 342L, 0L, 495L, 13L, 127L, 1415L, 1534L, 939L, 2315L, 649L, 154L, 2838L, 1462L, 2255L, 1058L, 316L, 1825L, 2391L, 324L, 185L, 813L, 997L, 830L, 407L, 796L, 624L, 1002L, 6L, 86L, 1091L, 1951L, 8L, 1863L, 2555L, 799L, 749L, 2386L, 1893L, 524L, 846L, 2263L, 2266L, 779L, 88L, 380L, 1495L, 1985L, 3L, 1462L, 1450L, 1L, 19L, 967L, 1565L, 1066L, 9L, 99L, 4L, 1889L, 1848L, 1924L, 471L, 1357L, 626L, 1465L, 1787L, 1437L, 115L, 322L, 717L, 1639L, 990L, 1029L, 1112L, 372L, 8L, 256L, 1679L, 1209L, 2246L, 2153L, 1762L, 1883L, 1551L, 998L, 728L, 1274L, 888L, 508L, 2357L, 452L, 1167L, 2385L, 3280L, 320L, 1130L, 878L, 583L, 799L, 4L, 61L, 394L, 1237L, 854L, 68L, 379L, 2910L, 3088L, 1011L, 840L, 1024L, 2496L, 3079L, 2830L, 1841L, 1772L, 595L, 65L, 584L, 2110L, 1966L, 473L, 21L, 847L, 293L, 881L, 840L, 1912L, 683L, 1362L, 1276L, 3131L, 3110L, 1773L, 1077L, 1437L, 769L, 2311L, 1623L, 562L, 42L, 1791L, 1318L, 1230L, 202L, 2630L, 623L, 918L, 48L, 523L, 721L, 1624L, 1047L, 1783L, 313L, 1042L, 2211L, 2430L, 1770L, 1610L, 2814L, 2460L, 1770L, 25L, 709L, 416L, 709L, 998L, 921L, 89L, 1174L, 396L, 52L, 2261L, 1237L, 56L, 927L, 2491L, 3180L, 352L, 81L, 2072L, 3207L, 2394L, 600L, 3280L, 1745L, 147L, 1L, 1544L, 350L, 2198L, 1833L, 55L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 258L, 1242L, 75L, 1131L, 893L, 402L, 381L, 51L, 15L, 47L, 762L, 777L, 479L, 2416L, 3639L, 1991L, 202L, 1054L, 917L, 1565L, 503L, 61L, 44L, 2103L, 2212L, 352L, 1L, 666L, 351L, 1321L, 7L, 1010L, 1222L, 1080L, 1643L, 1101L, 188L, 2793L, 1548L, 1811L, 1807L, 51L, 788L, 1108L, 1157L, 1038L, 225L, 454L, 441L, 376L, 444L, 5L, 501L, 579L, 1253L, 1600L, 1051L, 498L, 2217L, 2362L, 2425L, 1220L, 2037L, 2684L, 799L, 471L, 139L, 545L, 1117L, 177L, 487L, 1420L, 692L, 303L, 736L, 750L, 1386L, 926L, 30L, 862L, 1912L, 2731L, 1123L, 1160L, 2892L, 1634L, 585L, 3473L, 2243L, 441L, 399L, 1482L, 111L, 455L, 1315L, 691L, 1428L, 96L, 52L, 258L, 1135L, 1727L, 448L, 2148L, 358L, 2180L, 1519L, 2634L, 828L, 1212L, 1052L, 2851L, 902L, 171L, 236L, 3L, 727L, 1366L, 637L, 43L, 0L, 1320L, 146L, 664L, 862L, 663L, 227L, 227L, 995L, 743L, 1793L, 2421L, 1346L, 1874L, 2182L, 1333L, 1967L, 1023L, 297L, 340L, 1469L, 10L, 213L, 805L)), row.names = c(NA, -1008L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000000002641ef0>) Hope I can get some help to organize the data chronologically for the full dataset. Any input is appreciated.
This should help! act.byHour_corr$date <- as.Date(gsub('Activity on ', '', act.byHour_corr$date), format = '%m/%d/%Y') act.byHour_corr <- act.byHour_corr[order(act.byHour_corr$date),] It removes the 'Activity on' portion of the column. Does that work, or do you need to keep the 'Activity on' part?
Add hour to you data: library(data.table) library(lubridate) library(stringr) act.byHour_corr[, data_hour:=(paste0(date," ", str_pad(hour, 2, "left",0),":00"))] act.byHour_corr[, data_hour:=mdy_hm(data_hour)] act.byHour_corr[order(data_hour)]
Predict values for each group in gamm4
I have a data set like this: dat <- structure(list(Y = c(152.75, 167.7, 169.7, 173.2, 174.4, 177.1, 196, 200.45, 206.1, 206.65, 203, 186.65, 208.9, 192.95, 201.05, 203.45, 200.3, 197.55, 205.1, 198.1, 205.15, 189.35, 201.25, 194.55, 204.15, 200.95, 166.6, 165.1, 175.2, 168.4, 153, 168.4, 161, 170.1, 168.15, 167.3, 169.2, 169.25, 185.35, 185.9, 178.55, 193.2, 210.25, 203.75, 203.25, 203.7, 200.15, 204, 204, 206.3, 197.7, 190.5, 185.95, 199, 185.1, 194.35, 186.2, 190.95, 191.55, 177.8, 182.95, 186.3, 177.25, 186.35, 177.1, 183.9, 188.55, 184.05, 188.55, 187.25, 185.25, 174.8, 180.9, 171.4, 169.6, 176.7, 178.35, 191.3, 180.45, 187.5, 183.85, 187.7, 176.45, 188.7, 179.15, 183.25, 180.1, 184.35, 185.35, 184.25, 182.55, 185.15, 181.2, 184.6, 183.05, 182.35, 177.55, 179.85, 176.1, 175.9, 173.7, 180.7, 194.55, 190.3, 200.5, 193.05, 191.55, 190.65, 194.9, 192.8, 202.65, 200.35, 181.95, 194.85, 198.3, 199.7, 185.7, 195.9, 195.15, 191.85, 198.65, 188.9, 192.25, 197.8, 185.75, 193.5, 178.2, 170.15, 175.4, 176.25, 176.6, 179.8, 182, 173.35, 181.75, 188.05, 198.05, 204.75, 190.75, 196.15, 193.15, 195.4, 192.35, 165.55, 187.15, 191.35, 200.4, 200.4, 204.85, 211.3, 206.45, 205.95, 201, 198.6, 202.45, 192.95, 198.25, 190.85, 182.9, 184.5, 175.75, 174.95, 178.8, 173.2, 174, 176.75, 167.2, 161.1, 155.6, 178.6, 187.8, 194.05), X1 = c(4L, 6L, 7L, 8L, 9L, 10L, 4L, 6L, 7L, 8L, 9L, 10L, 11L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 12L, 13L, 14L, 15L, 4L, 5L, 6L, 7L, 8L, 4L, 5L, 6L, 7L, 11L, 14L, 15L, 16L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 4L, 5L, 9L, 13L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 4L, 5L, 7L, 8L, 9L, 10L, 11L, 12L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 4L, 5L, 8L, 9L, 10L, 11L, 4L, 5L, 6L, 7L, 8L, 10L, 11L, 12L, 13L, 4L, 6L, 7L, 8L, 9L, 12L, 13L, 14L, 15L, 16L, 17L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 12L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 4L, 6L, 7L, 4L, 5L, 7L, 9L, 11L, 12L, 15L, 16L, 17L, 20L, 21L, 22L, 4L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 16L, 18L, 4L, 5L, 6L), X2 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L), .Label = c("bec", "bi", "ebk", "ele", "eli", "ian", "isy", "ith", "lda", "lli", "na", "nja", "ra", "rda", "ria", "rik", "tje", "tri"), class = "factor")), .Names = c("Y", "X1", "X2"), row.names = c(142L, 143L, 144L, 145L, 146L, 147L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 82L, 83L, 84L, 85L, 86L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 133L, 134L, 135L, 136L, 137L, 138L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 130L, 131L, 132L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 139L, 140L, 141L), class = "data.frame") and I applied a gamm4-model from gamm4-package on it: library(gamm4) gamm.1 <- gamm4(Y ~ s(X1),random = ~(1+X1|X2),data = dat) I also predicted and plotted the smoothed values using: newDat <- data.frame(X1 = min(dat$X1):max(dat$X1)) p0 <- predict(gamm.1$gam,newDat,se=T) plot(dat$X1,dat$Y) lines(newDat$X1,p0$fit,lwd=3) My question is: how can I predict the smoothed lines for each of the groups (X2)? I know that I can get the random effects via ranef(gamm.1$mer) but I don't know how to use them correctly.
How to convert adjacency list to adjacency matrix in R?
I have adjacency list in the form of: 1. 3,4 2. 4 3. 1,4 4. 1,2,3 and I want to transform into adjacency matrix using R. I have tried various commands like transformation of adjacency list to igraph object and then retransformation of igraph to adjacency matrix, but the obtained adjacency matrix is S4 class. I want simple commands to transform adjacency list to adjacency matrix in R. data list(c(1L, 3L, 4L, 8L, 14L, 31L, 2L, 29L, 33L, 7L, 11L, 17L, 5L, 6L, 34L), c(2L, 3L, 4L, 8L, 9L, 12L, 13L, 14L, 18L, 22L, 1L, 10L, 33L, 34L), c(2L, 3L, 4L, 8L, 9L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 1L, 31L, 34L, 24L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 1L, 31L, 10L, 28L, 29L), c(4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 1L, 17L), c(4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 1L, 17L), c(4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 1L, 17L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 1L, 31L, 10L, 28L, 29L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 10L, 28L, 29L, 33L, 34L, 15L, 16L, 19L, 21L, 23L, 24L, 30L, 31L, 27L), c(2L, 4L, 8L, 9L, 10L, 14L, 28L, 29L, 33L, 15L, 16L, 19L, 20L, 21L, 23L, 24L, 27L, 30L, 31L, 32L), c(4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 1L, 17L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 1L, 31L, 10L, 28L, 29L, 33L, 15L, 16L, 19L, 21L, 23L, 24L, 27L, 30L), c(9L, 15L, 16L, 19L, 21L, 23L, 24L, 30L, 31L, 32L, 10L, 14L, 20L, 27L, 28L, 29L), c(9L, 15L, 16L, 19L, 21L, 23L, 24L, 30L, 31L, 32L, 10L, 14L, 20L, 27L, 28L, 29L), c(1L, 7L, 11L, 17L, 5L, 6L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 31L), c(9L, 15L, 16L, 19L, 21L, 23L, 24L, 30L, 31L, 32L, 10L, 14L, 20L, 27L, 28L, 29L ), c(3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 31L, 10L, 15L, 16L, 19L, 21L, 23L, 24L, 27L, 28L, 29L, 30L), c(9L, 15L, 16L, 19L, 21L, 23L, 24L, 30L, 31L, 32L, 10L, 14L, 20L, 27L, 28L, 29L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 31L ), c(9L, 15L, 16L, 19L, 21L, 23L, 24L, 30L, 31L, 32L, 10L, 14L, 20L, 27L, 28L, 29L), c(24L, 25L, 32L, 3L, 34L, 27L, 33L, 9L, 15L, 16L, 19L, 21L, 23L, 30L, 31L, 10L, 14L, 20L, 28L, 29L), c(24L, 25L, 32L, 34L, 26L, 29L), c(26L, 28L, 30L, 33L, 34L, 32L, 25L, 29L), c(24L, 27L, 33L, 9L, 10L, 14L, 15L, 16L, 19L, 20L, 21L, 23L, 28L, 29L, 30L, 31L, 32L), c(4L, 8L, 9L, 10L, 14L, 28L, 29L, 33L, 26L, 30L, 32L, 15L, 16L, 19L, 20L, 21L, 23L, 24L, 27L, 31L), c(1L, 4L, 8L, 9L, 10L, 14L, 28L, 29L, 33L, 25L, 26L, 15L, 16L, 19L, 20L, 21L, 23L, 24L, 27L, 30L, 31L, 32L), c(26L, 28L, 30L, 33L, 34L, 9L, 15L, 16L, 19L, 21L, 23L, 24L, 31L, 32L, 10L, 14L, 20L, 27L, 29L), c(1L, 3L, 4L, 8L, 14L, 18L, 20L, 22L, 31L, 33L, 34L, 9L, 15L, 16L, 19L, 21L, 23L, 24L, 30L, 32L, 10L, 27L, 28L, 29L), c(3L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 26L, 28L, 24L, 25L, 15L, 16L, 19L, 21L, 23L, 30L, 31L, 10L, 27L, 29L), c(1L, 2L, 9L, 10L, 14L, 28L, 29L, 33L, 31L, 34L, 26L, 30L, 24L, 27L), c(1L, 3L, 31L, 33L, 34L, 2L, 26L, 30L, 24L, 25L, 9L))
Suppose el is a list of edge list: el = list(c(3,4), c(2,4), c(1,4), c(1,2,3)) #Get the matrix dimension dim <- length(el) m <- sapply(el, function(x) { r<-rep(0,dim); r[unlist(x)]<-1;r}) [,1] [,2] [,3] [,4] [1,] 0 0 1 1 [2,] 0 1 0 1 [3,] 1 0 0 1 [4,] 1 1 1 0
Create and output multiple plots from list
I am attempting to create and output as pdfs a list of 64 items. My data takes the form: QQJAN List of 64 file1: List of 2 ..$x: num [1:161] 96.7 96.8 97.5 ... ..$y: num [1:161] 9.3 10.3 17.3 ... .................................................................. file64: List of 2 ..$x: num [1:161] 42.6 59.9 70.4 ... ..$y: num [1:161] 9.3 10.3 17.3 ... I can do this for any single item in the list using: plot(QQJAN$file1) and can then output these files to my working directory as pdfs, but how can all 64 files in the list be plotted and outputted with their names, i.e. file1.pdf, file 2.pdf etc. Can the lapply function be used here? A reproducible example: QQJAN$file1$x=c(1,2,3,4) QQJAN$file1$y=c(2,4,5,6) QQJAN$file2$x=c(2,2,3,5) QQJAN$file2$y=c(2,4,5,6)
Not tested due to lack of a reproducible example: for (i in seq_along(QQJAN)) { pdf(sprintf("plot%i.pdf", i)) #or pdf(paste0(names(QQJAN)[i], ".pdf")) plot(QQJAN[[i]]) dev.off() } If you are only interested in side effects, such as plotting, a for loop is usually appropriate. You should use lapply if you need a return value.
We can use lapply to loop over the names of the list elements, create the pdf file by pasteing the individual names with .pdf, subset the list (QQJAN[[x]]), plot. invisible(lapply(names(QQJAN), function(x) { pdf(paste0(x, '.pdf')) plot(QQJAN[[x]]) dev.off()})) data QQJAN <- structure(list(file1 = structure(list(x = c(6L, 5L, 15L, 11L, 14L, 19L, 6L, 16L, 17L, 6L, 13L, 8L, 14L, 14L, 7L, 19L, 4L, 1L, 11L, 3L, 2L, 12L, 15L, 3L, 5L, 14L, 2L, 12L, 13L, 1L, 7L, 5L, 8L, 3L, 19L, 5L, 15L, 13L, 14L, 20L), y = c(29L, 23L, 17L, 14L, 3L, 5L, 24L, 22L, 16L, 21L, 28L, 52L, 28L, 43L, 33L, 60L, 28L, 18L, 11L, 9L, 30L, 15L, 17L, 8L, 44L, 19L, 57L, 59L, 45L, 30L, 9L, 13L, 1L, 60L, 39L, 21L, 35L, 50L, 3L, 44L)), .Names = c("x", "y")), file2 = structure(list(x = c(11L, 3L, 11L, 5L, 8L, 7L, 6L, 18L, 8L, 17L, 7L, 15L, 19L, 3L, 10L, 12L, 13L, 2L, 9L, 10L, 15L, 13L, 3L, 6L, 16L, 1L, 20L, 5L, 9L, 4L, 12L, 1L, 6L, 13L, 18L, 7L, 18L, 19L, 15L, 13L), y = c(56L, 31L, 40L, 43L, 20L, 45L, 55L, 8L, 43L, 26L, 7L, 52L, 7L, 31L, 11L, 14L, 55L, 26L, 4L, 42L, 34L, 44L, 12L, 4L, 30L, 60L, 23L, 44L, 29L, 55L, 6L, 37L, 11L, 14L, 36L, 52L, 28L, 22L, 31L, 33L)), .Names = c("x", "y"))), .Names = c("file1", "file2"))