Error when dividing multiple columns by one column in R - r

This is a sample of the data I'm working with:
> head(tableresults)
ACTIVITY_X ACTIVITY_Y ACTIVITY_Z Vigilance Head-up Grazing Browsing Moving Grooming Resting
1: 40 47 62 0 41 0 0 0 0 0
2: 60 74 95 0 72 0 0 0 5 0
3: 62 63 88 0 80 0 0 0 0 0
4: 60 56 82 0 80 0 0 0 0 0
5: 66 61 90 0 80 0 0 0 0 0
6: 60 53 80 0 80 0 0 0 0 0
Fleeing Total Event winning_cluster
1: 0 41 Head-up cluster2
2: 0 80 Grooming cluster4
3: 0 80 Head-up cluster4
4: 0 80 Head-up cluster4
5: 0 80 Head-up cluster4
6: 0 80 Head-up cluster4
>
I simply would like to divide the values in columns Vigilance,Head-up,Grazing,Browsing,Moving,Grooming,Resting by the values in column Total. I'm using the following command but getting an error message. All columns have the same number of rows:
> tableresults[,4:11] / tableresults[,12]
Error in Ops.data.frame(tableresults[, 4:11], tableresults[, 12]) :
‘/’ only defined for equally-sized data frames
Am I doing something wrong? Any input is appreciated!
I'm providing the full dataset below as suggested in one of the comments:
> dput(tableresults)
structure(list(ACTIVITY_X = c(40L, 60L, 62L, 60L, 66L, 60L, 57L,
54L, 52L, 93L, 80L, 14L, 61L, 51L, 40L, 20L, 21L, 5L, 53L, 48L,
73L, 73L, 21L, 29L, 63L, 59L, 57L, 51L, 53L, 67L, 72L, 74L, 70L,
60L, 74L, 85L, 77L, 68L, 58L, 80L, 34L, 45L, 34L, 60L, 75L, 62L,
66L, 51L, 53L, 48L, 62L, 62L, 57L, 5L, 1L, 12L, 23L, 5L, 4L,
0L, 13L, 45L, 44L, 31L, 68L, 88L, 43L, 70L, 18L, 83L, 71L, 67L,
75L, 74L, 49L, 90L, 44L, 64L, 57L, 22L, 29L, 52L, 37L, 32L, 120L,
45L, 22L, 54L, 30L, 9L, 27L, 14L, 3L, 29L, 12L, 61L, 60L, 29L,
15L, 7L, 6L, 0L, 2L, 0L, 4L, 1L, 7L, 0L, 0L, 0L, 0L, 0L, 1L,
23L, 49L, 46L, 8L, 31L, 45L, 60L, 37L, 61L, 52L, 51L, 38L, 86L,
60L, 41L, 43L, 40L, 42L, 42L, 48L, 64L, 71L, 59L, 0L, 27L, 12L,
3L, 0L, 0L, 8L, 21L, 6L, 2L, 7L, 4L, 3L, 3L, 46L, 46L, 59L, 53L,
37L, 44L, 39L, 49L, 37L, 47L, 17L, 36L, 32L, 33L, 26L, 12L, 8L,
31L, 35L, 27L, 27L, 24L, 17L, 35L, 39L, 28L, 54L, 5L, 0L, 0L,
0L, 0L, 17L, 22L, 25L, 12L, 0L, 5L, 41L, 51L, 66L, 39L, 32L,
53L, 43L, 40L, 44L, 45L, 48L, 51L, 41L, 45L, 39L, 46L, 59L, 31L,
5L, 24L, 18L, 5L, 15L, 13L, 0L, 26L, 0L), ACTIVITY_Y = c(47L,
74L, 63L, 56L, 61L, 53L, 40L, 41L, 49L, 32L, 54L, 13L, 99L, 130L,
38L, 14L, 6L, 5L, 94L, 96L, 38L, 43L, 29L, 47L, 66L, 47L, 38L,
31L, 36L, 35L, 38L, 72L, 54L, 44L, 45L, 51L, 80L, 48L, 39L, 85L,
42L, 39L, 37L, 75L, 36L, 45L, 32L, 35L, 41L, 26L, 99L, 163L,
124L, 0L, 0L, 24L, 37L, 0L, 6L, 0L, 29L, 29L, 26L, 27L, 54L,
147L, 82L, 98L, 12L, 83L, 97L, 104L, 128L, 81L, 42L, 102L, 60L,
79L, 58L, 15L, 14L, 75L, 75L, 40L, 130L, 40L, 13L, 54L, 42L,
7L, 10L, 3L, 0L, 15L, 8L, 75L, 55L, 26L, 18L, 1L, 13L, 0L, 0L,
0L, 1L, 0L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 17L, 45L, 38L, 10L, 31L,
52L, 36L, 65L, 97L, 45L, 59L, 49L, 92L, 51L, 34L, 21L, 20L, 29L,
28L, 22L, 32L, 30L, 86L, 0L, 15L, 7L, 4L, 0L, 0L, 0L, 11L, 3L,
0L, 1L, 3L, 1L, 0L, 72L, 62L, 98L, 55L, 26L, 39L, 28L, 81L, 20L,
52L, 12L, 48L, 24L, 40L, 30L, 5L, 6L, 40L, 37L, 33L, 26L, 17L,
14L, 39L, 27L, 28L, 67L, 0L, 0L, 0L, 0L, 0L, 10L, 12L, 14L, 7L,
0L, 2L, 39L, 67L, 74L, 28L, 23L, 57L, 34L, 36L, 36L, 37L, 46L,
43L, 73L, 65L, 31L, 64L, 128L, 17L, 3L, 12L, 17L, 0L, 9L, 7L,
0L, 17L, 0L), ACTIVITY_Z = c(62L, 95L, 88L, 82L, 90L, 80L, 70L,
68L, 71L, 98L, 97L, 19L, 116L, 140L, 55L, 24L, 22L, 7L, 108L,
107L, 82L, 85L, 36L, 55L, 91L, 75L, 69L, 60L, 64L, 76L, 81L,
103L, 88L, 74L, 87L, 99L, 111L, 83L, 70L, 117L, 54L, 60L, 50L,
96L, 83L, 77L, 73L, 62L, 67L, 55L, 117L, 174L, 136L, 5L, 1L,
27L, 44L, 5L, 7L, 0L, 32L, 54L, 51L, 41L, 87L, 171L, 93L, 120L,
22L, 117L, 120L, 124L, 148L, 110L, 65L, 136L, 74L, 102L, 81L,
27L, 32L, 91L, 84L, 51L, 177L, 60L, 26L, 76L, 52L, 11L, 29L,
14L, 3L, 33L, 14L, 97L, 81L, 39L, 23L, 7L, 14L, 0L, 2L, 0L, 4L,
1L, 8L, 0L, 0L, 0L, 0L, 0L, 1L, 29L, 67L, 60L, 13L, 44L, 69L,
70L, 75L, 115L, 69L, 78L, 62L, 126L, 79L, 53L, 48L, 45L, 51L,
50L, 53L, 72L, 77L, 104L, 0L, 31L, 14L, 5L, 0L, 0L, 8L, 24L,
7L, 2L, 7L, 5L, 3L, 3L, 85L, 77L, 114L, 76L, 45L, 59L, 48L, 95L,
42L, 70L, 21L, 60L, 40L, 52L, 40L, 13L, 10L, 51L, 51L, 43L, 37L,
29L, 22L, 52L, 47L, 40L, 86L, 5L, 0L, 0L, 0L, 0L, 20L, 25L, 29L,
14L, 0L, 5L, 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L, 34L, 80L, 80L, 80L, 80L,
65L, 0L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 0L, 0L,
4L, 0L, 12L, 0L, 14L, 9L, 10L, 0L, 8L, 15L, 5L, 16L, 5L, 0L,
5L, 20L, 52L, 39L, 0L, 11L, 16L, 7L, 9L, 15L, 6L, 9L, 18L, 5L,
3L, 22L, 14L, 4L, 8L, 0L, 7L, 11L, 0L, 15L, 80L, 65L, 21L, 0L,
3L, 0L, 4L, 2L, 23L, 4L, 10L, 13L, 7L, 0L, 63L, 80L, 62L, 80L,
80L, 80L, 2L, 4L, 8L, 3L, 20L, 9L, 3L, 53L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 19L, 0L, 24L, 3L, 18L, 80L,
80L, 80L, 75L, 16L, 0L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 8L, 24L, 20L, 15L, 30L, 34L, 29L, 41L, 21L, 45L,
46L, 12L, 80L, 80L, 61L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 77L,
73L, 80L, 80L, 80L, 80L, 80L, 68L, 80L, 80L, 80L, 80L, 80L, 75L,
77L, 46L, 80L, 65L, 74L, 80L, 62L, 46L, 27L, 26L, 31L, 28L),
Grazing = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 22L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L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L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L), Event = c("Head-up",
"Grooming", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Vigilance", "Moving", "Moving", "Moving", "Moving", "Head-up",
"Head-up", "Head-up", "Head-up", "Moving", "Moving", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Grazing", "Grazing",
"Moving", "Moving", "Grazing", "Grazing", "Grazing", "Moving",
"Moving", "Grazing", "Grazing", "Grazing", "Grazing", "Grooming",
"Grooming", "Grazing", "Grazing", "Grooming", "Grooming",
"Grooming", "Vigilance", "Grazing", "Grazing", "Grazing",
"Grazing", "Vigilance", "Grazing", "Grazing", "Grazing",
"Grazing", "Moving", "Grazing", "Grazing", "Grazing", "Grazing",
"Grazing", "Moving", "Vigilance", "Vigilance", "Vigilance",
"Head-up", "Grazing", "Grazing", "Grazing", "Grazing", "Grazing",
"Grazing", "Grazing", "Grazing", "Grazing", "Grazing", "Grazing",
"Grazing", "Grazing", "Moving", "Head-up", "Vigilance", "Head-up",
"Head-up", "Head-up", "Grazing", "Grazing", "Grazing", "Grazing",
"Grazing", "Grooming", "Grazing", "Moving", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Moving", "Moving", "Vigilance",
"Vigilance", "Grazing", "Head-up", "Head-up", "Head-up",
"Moving", "Moving", "Grazing", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Grazing", "Grazing", "Grazing",
"Grazing", "Grazing", "Vigilance", "Grazing", "Grazing",
"Vigilance", "Vigilance", "Moving", "Moving", "Head-up",
"Head-up", "Moving", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Grooming", "Grooming",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Vigilance",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Grooming",
"Grooming", "Vigilance", "Head-up", "Vigilance", "Grooming",
"Head-up", "Vigilance", "Vigilance", "Vigilance", "Browsing",
"Moving", "Vigilance"), winning_cluster = c("cluster2", "cluster4",
"cluster4", "cluster4", "cluster4", "cluster4", "cluster4",
"cluster4", "cluster4", "cluster3", "cluster3", "cluster1",
"cluster3", "cluster3", "cluster2", "cluster1", "cluster1",
"cluster1", "cluster3", "cluster3", "cluster4", "cluster4",
"cluster2", "cluster2", "cluster4", "cluster4", "cluster4",
"cluster2", "cluster2", "cluster4", "cluster4", "cluster3",
"cluster4", "cluster4", "cluster4", "cluster3", "cluster3",
"cluster4", "cluster4", "cluster3", "cluster2", "cluster2",
"cluster2", "cluster4", "cluster4", "cluster4", "cluster4",
"cluster2", "cluster4", "cluster2", "cluster3", "cluster3",
"cluster3", "cluster1", "cluster1", "cluster1", "cluster2",
"cluster1", "cluster1", "cluster1", "cluster2", "cluster2",
"cluster2", "cluster2", "cluster4", "cluster3", "cluster4",
"cluster3", "cluster1", "cluster3", "cluster3", "cluster3",
"cluster3", "cluster3", "cluster2", "cluster3", "cluster4",
"cluster4", "cluster4", "cluster1", "cluster2", "cluster4",
"cluster4", "cluster2", "cluster3", "cluster2", "cluster1",
"cluster4", "cluster2", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster2", "cluster1", "cluster4", "cluster4",
"cluster2", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster2", "cluster2", "cluster2", "cluster1",
"cluster2", "cluster2", "cluster4", "cluster4", "cluster3",
"cluster4", "cluster4", "cluster2", "cluster3", "cluster4",
"cluster2", "cluster2", "cluster2", "cluster2", "cluster2",
"cluster2", "cluster4", "cluster4", "cluster4", "cluster1",
"cluster2", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster4", "cluster4",
"cluster3", "cluster4", "cluster2", "cluster2", "cluster2",
"cluster4", "cluster2", "cluster2", "cluster1", "cluster2",
"cluster2", "cluster2", "cluster2", "cluster1", "cluster1",
"cluster2", "cluster2", "cluster2", "cluster2", "cluster2",
"cluster1", "cluster2", "cluster2", "cluster2", "cluster4",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster2", "cluster4", "cluster3", "cluster2",
"cluster2", "cluster4", "cluster2", "cluster2", "cluster2",
"cluster2", "cluster2", "cluster4", "cluster4", "cluster4",
"cluster2", "cluster4", "cluster3", "cluster2", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster2", "cluster1")), row.names = c(NA, -215L
), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000000002541ef0>)```

You can use mutate_at to modify those fields as shown below:
> library(dplyr)
> tableresults <- tableresults %>%
mutate_at(.vars = vars(Vigilance:Fleeing),
.funs = funs(. / Total))
> head(tableresults)
ACTIVITY_X ACTIVITY_Y ACTIVITY_Z Vigilance Head-up Grazing Browsing Moving Grooming
1 40 47 62 0 1.0 0 0 0 0.0000
2 60 74 95 0 0.9 0 0 0 0.0625
3 62 63 88 0 1.0 0 0 0 0.0000
4 60 56 82 0 1.0 0 0 0 0.0000
5 66 61 90 0 1.0 0 0 0 0.0000
6 60 53 80 0 1.0 0 0 0 0.0000
Resting Fleeing Total Event winning_cluster
1 0 0 41 Head-up cluster2
2 0 0 80 Grooming cluster4
3 0 0 80 Head-up cluster4
4 0 0 80 Head-up cluster4
5 0 0 80 Head-up cluster4
6 0 0 80 Head-up cluster4

you can resolve with sweep function:
sweep(tableresults[,4:11], 2, tableresults[,12], `/`)
The simple operation / works only with one vector vs one vector. Instead You are trying to divide two vector vs one vector.

a simple solution:
tableresults[,4:11] / tableresults[[12]]
this will make the tableresults[[12]] a vector and that should work.

I think this is due to elementwise division on matrices of unequal size. Give the below a shot:
tableresults[ ,4:11] / rep(tableresults[ ,12], ncol(tableresults[ ,4:11]))

Related

Need help in ggplot doing multiple factor barplot with error bar

I have a data for which I like to plot a barplot with error bar.
My data is as below:
dput(level6.top35)
structure(list(patient = structure(c(3L, 3L, 3L, 1L, 1L, 1L,
4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L, 9L,
9L, 10L, 10L, 10L, 11L, 11L, 11L, 2L, 2L, 2L), .Label = c("P1",
"P10", "P11", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9"), class = "factor"),
visit = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("V1", "V2", "V3"), class = "factor"),
Bacteroides = c(11095L, 9981L, 2426L, 6107L, 14806L, 785L,
34127L, 27590L, 4699L, 42464L, 32146L, 321L, 611L, 402L,
455L, 5597L, 475L, 2842L, 481L, 11508L, 2125L, 842L, 960L,
3215L, 12118L, 10526L, 517L, 67434L, 82449L, 419L, 25643L,
4455L), Clostridium = c(53693L, 51961L, 89862L, 1122L, 3987L,
3095L, 3083L, 372L, 1628L, 4L, 13L, 11346L, 47803L, 10120L,
939L, 2280L, 11355L, 18642L, 4358L, 53L, 47L, 22L, 44L, 1897L,
9328L, 4394L, 4886L, 7025L, 175L, 1522L, 14776L, 30405L),
Turicibacter = c(25L, 0L, 10L, 9L, 0L, 0L, 4428L, 382L, 827L,
18L, 0L, 370L, 106L, 2180L, 5789L, 422L, 4355L, 1585L, 21205L,
567L, 131028L, 32389L, 14953L, 50692L, 3666L, 9811L, 1694L,
123L, 103L, 475L, 1038L, 0L), Haemophilus = c(31L, 27L, 13L,
2693L, 530L, 908L, 103L, 217L, 22L, 21743L, 7413L, 40763L,
1303L, 40182L, 52L, 67L, 18501L, 7547L, 28384L, 756L, 19L,
43928L, 19930L, 433L, 70L, 952L, 16796L, 4415L, 88L, 0L,
4607L, 507L), Streptococcus = c(303L, 160L, 168L, 1205L,
8360L, 12927L, 8380L, 1341L, 306L, 865L, 3490L, 137L, 428L,
427L, 5215L, 861L, 11635L, 15341L, 7306L, 12963L, 192L, 1646L,
2311L, 645L, 9880L, 9314L, 9091L, 6649L, 7283L, 26253L, 21089L,
39463L), Intestinibacter = c(14L, 16L, 0L, 17L, 11L, 32L,
4991L, 17L, 76L, 13L, 0L, 8182L, 14976L, 8062L, 7529L, 917L,
6612L, 14714L, 23287L, 26558L, 32L, 10L, 46L, 18307L, 7201L,
11970L, 6983L, 2963L, 2172L, 1812L, 0L, 1115L), Ruminococcus = c(3237L,
7853L, 95L, 4209L, 380L, 105L, 4141L, 18344L, 16L, 4000L,
2374L, 17L, 690L, 33L, 3393L, 7285L, 259L, 11344L, 69L, 5175L,
46L, 13L, 64L, 156L, 8923L, 19573L, 60L, 6626L, 7614L, 188L,
998L, 109L), Veillonella = c(630L, 318L, 512L, 302L, 1739L,
420L, 779L, 495L, 11L, 538L, 2857L, 338L, 466L, 1777L, 37L,
423L, 2597L, 1330L, 457L, 1720L, 239L, 4659L, 1864L, 188L,
1062L, 4061L, 279L, 723L, 291L, 11009L, 14337L, 7129L), Sutterella = c(65L,
46L, 25L, 27L, 0L, 62L, 20L, 16L, 38L, 8499L, 7987L, 35L,
78L, 37L, 21L, 84L, 12L, 238L, 39L, 1746L, 26L, 31L, 65L,
383L, 11200L, 565L, 50L, 40L, 17L, 14L, 1407L, 353L), Epulopiscium = c(0L,
0L, 0L, 0L, 0L, 12L, 0L, 0L, 0L, 0L, 0L, 14447L, 8925L, 7733L,
0L, 6L, 20L, 823L, 158L, 84L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L), Faecalibacterium = c(184L, 203L, 154L,
113L, 92L, 135L, 111L, 144L, 102L, 1297L, 21410L, 132L, 185L,
138L, 127L, 151L, 135L, 204L, 173L, 128L, 203L, 148L, 191L,
177L, 169L, 171L, 193L, 150L, 133L, 169L, 4444L, 404L), Bifidobacterium = c(2288L,
8161L, 63L, 605L, 169L, 95L, 46L, 71L, 72L, 876L, 2540L,
60L, 467L, 73L, 578L, 1537L, 79L, 5413L, 73L, 543L, 127L,
86L, 144L, 76L, 775L, 71L, 84L, 80L, 64L, 47L, 49L, 70L),
Tyzzerella = c(18L, 0L, 0L, 559L, 0L, 0L, 1408L, 1666L, 0L,
86L, 373L, 0L, 373L, 0L, 439L, 235L, 107L, 21L, 0L, 0L, 0L,
0L, 25L, 134L, 4126L, 12034L, 4L, 0L, 0L, 0L, 47L, 0L), Lactobacillus = c(0L,
0L, 0L, 0L, 0L, 14L, 0L, 0L, 0L, 0L, 0L, 5L, 11L, 4L, 39L,
25L, 321L, 56L, 0L, 36L, 0L, 5L, 0L, 5L, 848L, 63L, 0L, 138L,
538L, 3801L, 122L, 4373L), Serratia = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 128L, 69L, 0L, 0L, 0L, 0L, 0L, 226L, 0L,
0L, 0L, 0L, 0L, 7828L, 0L, 0L, 0L, 0L, 70L, 0L, 0L, 0L, 0L
), Rothia = c(0L, 0L, 11L, 6L, 16L, 24L, 0L, 0L, 5L, 0L,
0L, 0L, 0L, 10L, 0L, 9L, 11L, 140L, 267L, 175L, 0L, 190L,
4617L, 0L, 0L, 0L, 1362L, 19L, 47L, 518L, 21L, 34L), Anaerosporobacter = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 256L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 31L, 3239L, 3546L, 0L, 0L,
0L, 0L, 0L, 0L), Erysipelatoclostridium = c(19L, 0L, 7L,
184L, 194L, 23L, 320L, 129L, 7L, 1151L, 436L, 20L, 52L, 0L,
862L, 1365L, 88L, 20L, 0L, 263L, 9L, 6L, 71L, 46L, 1175L,
217L, 0L, 190L, 98L, 0L, 72L, 26L), Paeniclostridium = c(0L,
0L, 0L, 0L, 303L, 0L, 0L, 0L, 0L, 0L, 0L, 129L, 9L, 339L,
0L, 0L, 66L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5167L, 228L,
221L, 0L, 0L, 0L), Blautia = c(526L, 132L, 101L, 87L, 19L,
97L, 93L, 118L, 71L, 204L, 1356L, 70L, 105L, 84L, 71L, 144L,
88L, 649L, 136L, 627L, 156L, 88L, 142L, 83L, 139L, 138L,
134L, 122L, 81L, 99L, 98L, 125L), Anaerostipes = c(27L, 38L,
25L, 20L, 10L, 24L, 17L, 21L, 0L, 709L, 4603L, 23L, 24L,
20L, 0L, 178L, 18L, 30L, 42L, 24L, 29L, 16L, 37L, 23L, 57L,
39L, 29L, 29L, 16L, 26L, 25L, 27L), Enterococcus = c(31L,
32L, 26L, 126L, 68L, 2498L, 70L, 31L, 26L, 0L, 15L, 59L,
57L, 23L, 395L, 758L, 133L, 0L, 0L, 27L, 50L, 36L, 56L, 21L,
39L, 0L, 422L, 159L, 20L, 24L, 96L, 95L), Citrobacter = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 3583L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 37L, 0L, 0L, 0L, 1088L, 0L, 0L, 0L, 0L, 0L, 144L,
0L, 0L, 0L, 0L), Prevotella = c(155L, 168L, 87L, 153L, 95L,
121L, 100L, 125L, 152L, 307L, 124L, 100L, 84L, 117L, 91L,
168L, 128L, 137L, 130L, 98L, 139L, 114L, 252L, 84L, 159L,
106L, 140L, 201L, 114L, 126L, 160L, 125L), Roseburia = c(621L,
19L, 0L, 0L, 0L, 0L, 0L, 18L, 0L, 46L, 32L, 17L, 13L, 0L,
0L, 36L, 17L, 160L, 0L, 109L, 18L, 15L, 22L, 77L, 1505L,
559L, 38L, 26L, 12L, 22L, 849L, 90L), Parabacteroides = c(60L,
18L, 12L, 114L, 9L, 49L, 349L, 593L, 60L, 158L, 162L, 46L,
53L, 42L, 17L, 33L, 29L, 197L, 49L, 458L, 42L, 45L, 83L,
271L, 479L, 429L, 51L, 63L, 76L, 0L, 85L, 47L), Neisseria = c(0L,
0L, 0L, 77L, 0L, 0L, 0L, 12L, 0L, 9L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 454L, 2L, 0L, 0L, 771L, 2662L, 4L, 0L, 11L, 10L,
0L, 0L, 0L, 0L, 0L), Actinobacillus = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 2670L, 149L, 0L, 0L, 0L, 0L, 0L, 0L, 130L,
0L, 0L, 0L, 0L, 0L, 10L, 0L, 60L, 0L, 0L, 0L, 0L, 0L, 0L),
Granulicatella = c(59L, 27L, 22L, 18L, 22L, 14L, 19L, 36L,
76L, 37L, 0L, 0L, 0L, 61L, 60L, 24L, 93L, 90L, 457L, 60L,
52L, 42L, 215L, 0L, 40L, 45L, 665L, 14L, 27L, 260L, 34L,
46L), Actinomyces = c(52L, 27L, 12L, 8L, 8L, 16L, 36L, 16L,
89L, 12L, 23L, 13L, 0L, 53L, 18L, 0L, 30L, 112L, 624L, 89L,
12L, 45L, 116L, 11L, 58L, 12L, 587L, 65L, 47L, 135L, 18L,
35L), Lachnoclostridium = c(21L, 19L, 17L, 37L, 0L, 0L, 211L,
337L, 13L, 361L, 184L, 0L, 12L, 12L, 19L, 91L, 0L, 66L, 0L,
228L, 44L, 9L, 0L, 77L, 293L, 257L, 0L, 0L, 0L, 0L, 28L,
20L), Pediococcus = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2101L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 9L, 0L, 0L, 0L, 0L, 0L, 0L), Fusobacterium = c(84L,
51L, 55L, 551L, 12L, 19L, 22L, 54L, 23L, 41L, 40L, 21L, 17L,
14L, 14L, 78L, 18L, 228L, 88L, 35L, 75L, 43L, 162L, 24L,
39L, 25L, 90L, 15L, 21L, 56L, 24L, 36L), Alistipes = c(68L,
81L, 24L, 69L, 35L, 66L, 40L, 57L, 60L, 86L, 72L, 48L, 47L,
60L, 51L, 92L, 48L, 67L, 72L, 36L, 40L, 65L, 137L, 21L, 31L,
65L, 84L, 100L, 93L, 42L, 81L, 41L), Eubacterium = c(0L,
7L, 0L, 0L, 0L, 0L, 0L, 0L, 8L, 12L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L)), .Names = c("patient", "visit", "Bacteroides", "Clostridium",
"Turicibacter", "Haemophilus", "Streptococcus", "Intestinibacter",
"Ruminococcus", "Veillonella", "Sutterella", "Epulopiscium",
"Faecalibacterium", "Bifidobacterium", "Tyzzerella", "Lactobacillus",
"Serratia", "Rothia", "Anaerosporobacter", "Erysipelatoclostridium",
"Paeniclostridium", "Blautia", "Anaerostipes", "Enterococcus",
"Citrobacter", "Prevotella", "Roseburia", "Parabacteroides",
"Neisseria", "Actinobacillus", "Granulicatella", "Actinomyces",
"Lachnoclostridium", "Pediococcus", "Fusobacterium", "Alistipes",
"Eubacterium"), class = "data.frame", row.names = c("AA_001_20-4-16",
"AA_001-V2", "AA_001_19-5-16", "AA_ISS-01-V1", "AA_ISS-01-V2",
"AA_ISS-01-V3", "AA_ISS-02-V1", "AA_ISS-02-V2", "AA_ISS-02-V3",
"AA_ISS-03-V1", "AA_ISS-03-V2", "AA_ISS-04-V1", "AA_ISS-04-V2",
"AA_ISS-04-V3", "AA_ISS-05-V1", "AA_ISS-05-V2", "AA_ISS-05-V3",
"AA_ISS-06-V1", "AA_ISS-06-V2", "AA_ISS-06-V3", "AA_ISS-07-V1",
"AA_ISS-07-V2", "AA_ISS-07-V3", "AA_ISS-08-V1", "AA_ISS-08-V2",
"AA_ISS-08-V3", "AA_ISS-09-V1", "AA_ISS-09-V2", "AA_ISS-09-V3",
"AA_ISS-10-V1", "AA_ISS-10-V2", "AA_ISS-10-V3"))
So far I have tried to reshape the data and few tries to plot them properly. But in vain.
library(reshape2)
df1<-melt(level6.top35, id.vars = c("patient","visit"))
ggplot(data=df1,aes(x=variable,y=value, fill=visit))+geom_bar(position="dodge",stat="identity")
+geom_errorbar( aes(x=variable, ymin=value-sd, ymax=value+sd), width=0.4, colour="orange", alpha=0.9, size=1.3)
I have managed to do the plot but not the errorbar. Ideally I like to have a barplot with the error bar.
You need to summarise the data and then add the error bars, e.g. like this:
df1 <- melt(level6.top35, id.vars = c("patient","visit"))
df1 %>% group_by(visit, variable) %>%
summarise(SD = sd(value), value = mean(value)) %>% ungroup() %>%
ggplot(., aes(x=variable, y=value, fill = visit)) +
geom_bar(stat="identity", position = "dodge") +
geom_errorbar(aes(ymin= value - SD, ymax = value + SD, width=0.2),
position=position_dodge(width=0.90)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
labs(x="Species")
It is still up to you to decide whether you want to just plot the positive bars, limit the y axis to avoid negative values, etc..

Subset, or reclassify, spatial data in R

I have the following data that indicates how many points occur within each rectangle (spatial data generated with quadratcount() from the spatstat package):
structure(c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 14L, 2L, 62L, 164L, 0L, 34L, 16L, 219L,
16L, 5L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 257L, 553L, 58L, 161L,
169L, 78L, 39L, 8L, 0L, 0L, 49L, 8L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 8L, 216L,
791L, 627L, 208L, 205L, 0L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,
0L, 15L, 0L, 1L, 0L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 140L, 282L, 395L, 112L,
184L, 194L, 244L, 0L, 0L, 14L, 136L, 217L, 11L, 20L, 40L, 114L,
597L, 227L, 146L, 55L, 7L, 12L, 5L, 0L, 6L, 16L, 252L, 201L,
9L, 5L, 0L, 55L, 0L, 17L, 9L, 20L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 98L, 480L, 270L, 0L, 109L, 298L,
385L, 9L, 0L, 0L, 8L, 196L, 247L, 86L, 184L, 422L, 628L, 357L,
0L, 0L, 0L, 9L, 0L, 0L, 11L, 0L, 255L, 206L, 88L, 0L, 41L, 224L,
4L, 0L, 106L, 2L, 0L, 2L, 1L, 18L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 7L, 21L, 8L, 3L, 0L, 0L, 85L, 0L, 0L, 0L, 0L, 42L,
319L, 141L, 351L, 421L, 810L, 331L, 0L, 0L, 0L, 216L, 67L, 18L,
0L, 96L, 313L, 2L, 41L, 17L, 17L, 45L, 0L, 0L, 0L, 2L, 2L, 0L,
0L, 68L, 353L, 122L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 65L,
141L, 72L, 32L, 49L, 34L, 0L, 6L, 5L, 0L, 82L, 309L, 343L, 0L,
253L, 473L, 22L, 0L, 0L, 0L, 0L, 187L, 163L, 2L, 270L, 4L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 9L, 7L, 0L, 0L, 38L, 10L, 151L, 117L,
25L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 28L, 14L, 416L, 29L, 164L, 93L,
120L, 202L, 203L, 6L, 0L, 0L, 210L, 538L, 178L, 183L, 416L, 51L,
0L, 0L, 0L, 0L, 98L, 152L, 115L, 289L, 18L, 81L, 3L, 0L, 0L,
0L, 35L, 7L, 0L, 2L, 29L, 0L, 0L, 14L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 40L, 0L, 0L, 107L, 312L, 322L, 192L, 361L, 694L,
555L, 17L, 0L, 0L, 12L, 319L, 131L, 920L, 394L, 48L, 230L, 0L,
0L, 0L, 0L, 19L, 154L, 146L, 9L, 8L, 32L, 20L, 4L, 48L, 0L, 0L,
16L, 0L, 345L, 68L, 0L, 0L, 0L, 12L, 2L, 0L, 0L, 0L, 0L, 15L,
0L, 5L, 0L, 0L, 0L, 208L, 131L, 332L, 419L, 117L, 448L, 144L,
0L, 75L, 83L, 53L, 360L, 8L, 29L, 685L, 749L, 134L, 8L, 0L, 33L,
0L, 0L, 86L, 38L, 7L, 0L, 170L, 202L, 118L, 94L, 238L, 326L,
115L, 244L, 62L, 0L, 0L, 5L, 0L, 1L, 0L, 7L, 0L, 1L, 0L, 0L,
26L, 6L, 0L, 0L, 5L, 183L, 396L, 45L, 0L, 80L, 0L, 0L, 172L,
629L, 143L, 418L, 51L, 36L, 603L, 834L, 549L, 91L, 156L, 12L,
0L, 0L, 0L, 0L, 5L, 129L, 17L, 108L, 299L, 161L, 177L, 30L, 0L,
64L, 57L, 0L, 0L, 0L, 0L, 0L, 0L, 59L, 5L, 62L, 111L, 36L, 2L,
24L, 0L, 0L, 98L, 26L, 140L, 0L, 12L, 0L, 24L, 0L, 53L, 199L,
406L, 413L, 107L, 678L, 1066L, 960L, 575L, 391L, 622L, 372L,
76L, 0L, 0L, 0L, 0L, 0L, 208L, 171L, 16L, 17L, 22L, 0L, 15L,
0L, 0L, 4L, 2L, 0L, 11L, 0L, 17L, 45L, 0L, 0L, 67L, 0L, 0L, 66L,
9L, 0L, 0L, 0L, 9L, 0L, 0L, 50L, 110L, 33L, 0L, 2L, 247L, 647L,
375L, 696L, 466L, 1367L, 1066L, 442L, 664L, 636L, 467L, 32L,
0L, 0L, 0L, 17L, 10L, 30L, 55L, 71L, 177L, 149L, 44L, 5L, 0L,
3L, 2L, 2L, 2L, 7L, 0L, 135L, 0L, 46L, 47L, 240L, 228L, 20L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 598L, 379L, 0L, 0L, 79L, 696L,
510L, 83L, 203L, 351L, 1030L, 900L, 646L, 610L, 635L, 347L, 18L,
1L, 0L, 59L, 0L, 0L, 0L, 0L, 9L, 26L, 31L, 11L, 2L, 0L, 3L, 0L,
0L, 0L, 0L, 0L, 0L, 234L, 8L, 147L, 51L, 0L, 0L, 0L, 0L, 0L,
7L, 66L, 0L, 0L, 376L, 953L, 366L, 236L, 217L, 228L, 518L, 509L,
112L, 140L, 437L, 562L, 354L, 763L, 697L, 408L, 310L, 54L, 28L,
0L, 0L, 0L, 10L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 10L, 10L, 0L, 0L,
0L, 0L, 25L, 69L, 171L, 315L, 12L, 4L, 0L, 0L, 7L, 0L, 0L, 0L,
0L, 35L, 406L, 394L, 802L, 469L, 852L, 6L, 371L, 451L, 742L,
245L, 728L, 1115L, 544L, 681L, 901L, 645L, 457L, 517L, 161L,
0L, 0L, 0L, 0L, 4L, 0L, 77L, 0L, 0L, 0L, 32L, 0L, 0L, 61L, 0L,
0L, 0L, 18L, 235L, 280L, 35L, 0L, 42L, 0L, 4L, 12L, 0L, 3L, 12L,
12L, 70L, 215L, 53L, 402L, 544L, 0L, 55L, 105L, 543L, 875L, 687L,
459L, 1110L, 1732L, 1411L, 725L, 771L, 587L, 829L, 69L, 0L, 0L,
23L, 334L, 387L, 416L, 355L, 367L, 160L, 0L, 0L, 4L, 0L, 0L,
0L, 0L, 0L, 19L, 326L, 69L, 0L, 9L, 165L, 43L, 110L, 44L, 67L,
0L, 37L, 0L, 0L, 310L, 0L, 83L, 408L, 183L, 8L, 169L, 560L, 625L,
916L, 345L, 758L, 1118L, 1258L, 1133L, 819L, 922L, 226L, 0L,
43L, 86L, 153L, 188L, 22L, 93L, 411L, 434L, 255L, 238L, 278L,
282L, 161L, 1L, 0L, 0L, 0L, 17L, 10L, 0L, 0L, 49L, 21L, 97L,
531L, 436L, 271L, 28L, 1L, 12L, 0L, 0L, 2L, 317L, 667L, 396L,
9L, 3L, 719L, 1070L, 768L, 1496L, 938L, 1135L, 1432L, 367L, 703L,
824L, 557L, 517L, 426L, 476L, 530L, 517L, 184L, 759L, 124L, 178L,
477L, 499L, 155L, 197L, 257L, 35L, 8L, 77L, 21L, 1L, 0L, 0L,
0L, 0L, 0L, 1L, 248L, 480L, 26L, 19L, 128L, 9L, 220L, 364L, 183L,
490L, 669L, 656L, 447L, 589L, 682L, 893L, 693L, 861L, 1117L,
1142L, 1403L, 1256L, 1185L, 680L, 232L, 268L, 520L, 586L, 325L,
520L, 278L, 648L, 10L, 317L, 409L, 290L, 234L, 50L, 166L, 50L,
22L, 140L, 192L, 75L, 0L, 0L, 0L, 0L, 0L, 0L, 65L, 10L, 43L,
0L, 6L, 138L, 645L, 632L, 372L, 739L, 720L, 552L, 256L, 637L,
705L, 896L, 981L, 711L, 820L, 1486L, 1377L, 1028L, 106L, 556L,
0L, 0L, 0L, 22L, 124L, 344L, 456L, 197L, 125L, 214L, 348L, 58L,
46L, 8L, 9L, 144L, 546L, 259L, 177L, 20L, 0L, 10L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 6L, 0L, 60L, 679L, 438L, 707L, 1002L, 846L, 832L,
834L, 262L, 561L, 499L, 768L, 877L, 1185L, 1597L, 1041L, 876L,
680L, 186L, 0L, 0L, 0L, 0L, 0L, 18L, 282L, 312L, 384L, 391L,
61L, 244L, 213L, 129L, 9L, 0L, 111L, 333L, 181L, 0L, 0L, 0L,
0L, 0L, 31L, 0L, 0L, 0L, 0L, 18L, 0L, 153L, 475L, 633L, 197L,
561L, 555L, 529L, 691L, 456L, 40L, 71L, 286L, 660L, 624L, 438L,
673L, 524L, 1055L, 957L, 492L, 77L, 0L, 0L, 0L, 0L, 0L, 0L, 218L,
383L, 317L, 239L, 298L, 110L, 163L, 55L, 64L, 176L, 184L, 0L,
4L, 0L, 4L, 0L, 0L, 0L, 158L, 194L, 0L, 73L, 607L, 786L, 575L,
570L, 125L, 564L, 635L, 632L, 515L, 0L, 0L, 0L, 15L, 371L, 513L,
589L, 804L, 808L, 916L, 645L, 944L, 260L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 2L, 56L, 231L, 260L, 255L, 287L, 330L, 267L, 72L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 430L, 717L, 0L, 169L, 713L, 597L,
621L, 402L, 40L, 201L, 458L, 615L, 438L, 0L, 0L, 0L, 0L, 52L,
274L, 352L, 334L, 622L, 720L, 596L, 167L, 406L, 318L, 54L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 102L, 706L, 517L, 636L, 85L,
0L, 0L, 0L, 0L, 0L, 5L, 0L, 60L, 18L, 109L, 338L, 577L, 178L,
307L, 310L, 237L, 3L, 182L, 84L, 502L, 499L, 79L, 0L, 0L, 0L,
189L, 233L, 31L, 162L, 87L, 350L, 422L, 370L, 357L, 208L, 239L,
207L, 158L, 19L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 212L, 266L,
0L, 0L, 0L, 0L, 18L, 66L, 247L, 163L, 211L, 798L, 199L, 619L,
55L, 0L, 249L, 264L, 399L, 44L, 453L, 78L, 844L, 652L, 24L, 0L,
0L, 112L, 129L, 55L, 69L, 43L, 64L, 93L, 193L, 322L, 510L, 399L,
358L, 333L, 208L, 103L, 371L, 138L, 60L, 10L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 2L, 136L, 122L, 209L, 300L, 556L, 365L,
212L, 107L, 0L, 0L, 0L, 93L, 270L, 450L, 223L, 723L, 651L, 428L,
50L, 0L, 0L, 23L, 0L, 77L, 0L, 0L, 0L, 485L, 103L, 140L, 224L,
121L, 163L, 93L, 197L, 186L, 272L, 575L, 337L, 107L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 312L, 572L, 389L,
541L, 0L, 0L, 0L, 0L, 18L, 285L, 454L, 542L, 224L, 463L, 688L,
120L, 58L, 0L, 114L, 0L, 22L, 0L, 2L, 111L, 629L, 210L, 0L, 172L,
0L, 0L, 0L, 0L, 112L, 160L, 180L, 275L, 498L, 240L, 72L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 92L, 186L, 216L, 41L,
0L, 0L, 0L, 0L, 186L, 572L, 333L, 401L, 492L, 124L, 175L, 318L,
74L, 35L, 345L, 38L, 0L, 0L, 0L, 255L, 422L, 358L, 85L, 214L,
216L, 0L, 0L, 3L, 87L, 49L, 72L, 114L, 117L, 184L, 4L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 3L, 0L, 237L, 19L, 0L, 0L,
0L, 0L, 135L, 198L, 358L, 373L, 231L, 146L, 421L, 428L, 4L, 0L,
118L, 77L, 0L, 0L, 0L, 26L, 304L, 457L, 129L, 285L, 198L, 28L,
0L, 229L, 227L, 114L, 0L, 83L, 16L, 232L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L, 183L, 91L, 0L, 0L, 0L, 2L,
111L, 4L, 76L, 238L, 132L, 460L, 435L, 777L, 194L, 0L, 10L, 121L,
128L, 0L, 0L, 0L, 0L, 24L, 9L, 265L, 263L, 1L, 0L, 35L, 170L,
30L, 0L, 0L, 30L, 59L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 11L, 208L, 16L, 0L, 1L, 188L, 449L, 311L, 243L,
203L, 64L, 457L, 493L, 615L, 361L, 94L, 1L, 78L, 0L, 0L, 0L,
44L, 0L, 0L, 0L, 83L, 18L, 167L, 184L, 116L, 0L, 0L, 0L, 0L,
0L, 15L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
10L, 244L, 442L, 225L, 45L, 39L, 362L, 206L, 403L, 348L, 118L,
21L, 356L, 515L, 547L, 194L, 181L, 0L, 0L, 0L, 0L, 89L, 224L,
61L, 0L, 0L, 46L, 6L, 200L, 225L, 103L, 92L, 20L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 50L,
343L, 408L, 0L, 14L, 68L, 547L, 472L, 139L, 40L, 312L, 280L,
634L, 380L, 125L, 19L, 0L, 39L, 2L, 54L, 92L, 27L, 316L, 150L,
0L, 0L, 0L, 7L, 90L, 320L, 62L, 0L, 5L, 6L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 178L, 529L, 44L,
0L, 71L, 276L, 170L, 186L, 0L, 17L, 0L, 14L, 185L, 185L, 34L,
21L, 0L, 132L, 75L, 46L, 18L, 178L, 49L, 12L, 2L, 0L, 0L, 50L,
178L, 89L, 3L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 201L, 42L, 51L, 227L, 37L, 72L,
71L, 140L, 169L, 0L, 0L, 163L, 41L, 3L, 0L, 0L, 264L, 387L, 8L,
246L, 289L, 149L, 293L, 107L, 0L, 0L, 61L, 32L, 39L, 18L, 21L,
4L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 152L, 124L, 0L, 0L, 31L, 356L, 121L, 46L,
0L, 145L, 119L, 0L, 23L, 146L, 69L, 298L, 220L, 0L, 93L, 249L,
227L, 55L, 0L, 0L, 0L, 0L, 134L, 4L, 0L, 3L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L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, 0L, 0L, 0L, 45L, 90L,
117L, 483L, 340L, 6L, 0L, 0L, 0L, 0L, 0L, 7L, 0L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 117L, 156L, 98L, 10L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), .Dim = c(50L,
50L), .Dimnames = list(y = c("[1.2588e+06,1.2593e+06]", "[1.2584e+06,1.2588e+06)",
"[1.2579e+06,1.2584e+06)", "[1.2575e+06,1.2579e+06)", "[1.257e+06,1.2575e+06)",
"[1.2566e+06,1.257e+06)", "[1.2561e+06,1.2566e+06)", "[1.2557e+06,1.2561e+06)",
"[1.2552e+06,1.2557e+06)", "[1.2548e+06,1.2552e+06)", "[1.2543e+06,1.2548e+06)",
"[1.2539e+06,1.2543e+06)", "[1.2534e+06,1.2539e+06)", "[1.253e+06,1.2534e+06)",
"[1.2525e+06,1.253e+06)", "[1.2521e+06,1.2525e+06)", "[1.2516e+06,1.2521e+06)",
"[1.2512e+06,1.2516e+06)", "[1.2507e+06,1.2512e+06)", "[1.2503e+06,1.2507e+06)",
"[1.2498e+06,1.2503e+06)", "[1.2494e+06,1.2498e+06)", "[1.2489e+06,1.2494e+06)",
"[1.2485e+06,1.2489e+06)", "[1.248e+06,1.2485e+06)", "[1.2476e+06,1.248e+06)",
"[1.2471e+06,1.2476e+06)", "[1.2467e+06,1.2471e+06)", "[1.2462e+06,1.2467e+06)",
"[1.2458e+06,1.2462e+06)", "[1.2453e+06,1.2458e+06)", "[1.2449e+06,1.2453e+06)",
"[1.2444e+06,1.2449e+06)", "[1.244e+06,1.2444e+06)", "[1.2435e+06,1.244e+06)",
"[1.2431e+06,1.2435e+06)", "[1.2426e+06,1.2431e+06)", "[1.2422e+06,1.2426e+06)",
"[1.2417e+06,1.2422e+06)", "[1.2413e+06,1.2417e+06)", "[1.2408e+06,1.2413e+06)",
"[1.2404e+06,1.2408e+06)", "[1.2399e+06,1.2404e+06)", "[1.2395e+06,1.2399e+06)",
"[1.239e+06,1.2395e+06)", "[1.2386e+06,1.239e+06)", "[1.2381e+06,1.2386e+06)",
"[1.2377e+06,1.2381e+06)", "[1.2372e+06,1.2377e+06)", "[1.2368e+06,1.2372e+06)"
), x = c("[2.6713e+06,2.6718e+06)", "[2.6718e+06,2.6722e+06)",
"[2.6722e+06,2.6727e+06)", "[2.6727e+06,2.6732e+06)", "[2.6732e+06,2.6736e+06)",
"[2.6736e+06,2.6741e+06)", "[2.6741e+06,2.6746e+06)", "[2.6746e+06,2.675e+06)",
"[2.675e+06,2.6755e+06)", "[2.6755e+06,2.676e+06)", "[2.676e+06,2.6764e+06)",
"[2.6764e+06,2.6769e+06)", "[2.6769e+06,2.6774e+06)", "[2.6774e+06,2.6778e+06)",
"[2.6778e+06,2.6783e+06)", "[2.6783e+06,2.6788e+06)", "[2.6788e+06,2.6792e+06)",
"[2.6792e+06,2.6797e+06)", "[2.6797e+06,2.6802e+06)", "[2.6802e+06,2.6806e+06)",
"[2.6806e+06,2.6811e+06)", "[2.6811e+06,2.6816e+06)", "[2.6816e+06,2.682e+06)",
"[2.682e+06,2.6825e+06)", "[2.6825e+06,2.683e+06)", "[2.683e+06,2.6834e+06)",
"[2.6834e+06,2.6839e+06)", "[2.6839e+06,2.6844e+06)", "[2.6844e+06,2.6848e+06)",
"[2.6848e+06,2.6853e+06)", "[2.6853e+06,2.6858e+06)", "[2.6858e+06,2.6862e+06)",
"[2.6862e+06,2.6867e+06)", "[2.6867e+06,2.6872e+06)", "[2.6872e+06,2.6876e+06)",
"[2.6876e+06,2.6881e+06)", "[2.6881e+06,2.6886e+06)", "[2.6886e+06,2.689e+06)",
"[2.689e+06,2.6895e+06)", "[2.6895e+06,2.6899e+06)", "[2.6899e+06,2.6904e+06)",
"[2.6904e+06,2.6909e+06)", "[2.6909e+06,2.6913e+06)", "[2.6913e+06,2.6918e+06)",
"[2.6918e+06,2.6923e+06)", "[2.6923e+06,2.6927e+06)", "[2.6927e+06,2.6932e+06)",
"[2.6932e+06,2.6937e+06)", "[2.6937e+06,2.6941e+06)", "[2.6941e+06,2.6946e+06]"
)), class = c("quadratcount", "table"), xbreaks = c(2671317,
2671782.76, 2672248.52, 2672714.28, 2673180.04, 2673645.8, 2674111.56,
2674577.32, 2675043.08, 2675508.84, 2675974.6, 2676440.36, 2676906.12,
2677371.88, 2677837.64, 2678303.4, 2678769.16, 2679234.92, 2679700.68,
2680166.44, 2680632.2, 2681097.96, 2681563.72, 2682029.48, 2682495.24,
2682961, 2683426.76, 2683892.52, 2684358.28, 2684824.04, 2685289.8,
2685755.56, 2686221.32, 2686687.08, 2687152.84, 2687618.6, 2688084.36,
2688550.12, 2689015.88, 2689481.64, 2689947.4, 2690413.16, 2690878.92,
2691344.68, 2691810.44, 2692276.2, 2692741.96, 2693207.72, 2693673.48,
2694139.24, 2694605), ybreaks = c(1236783, 1237233.14, 1237683.28,
1238133.42, 1238583.56, 1239033.7, 1239483.84, 1239933.98, 1240384.12,
1240834.26, 1241284.4, 1241734.54, 1242184.68, 1242634.82, 1243084.96,
1243535.1, 1243985.24, 1244435.38, 1244885.52, 1245335.66, 1245785.8,
1246235.94, 1246686.08, 1247136.22, 1247586.36, 1248036.5, 1248486.64,
1248936.78, 1249386.92, 1249837.06, 1250287.2, 1250737.34, 1251187.48,
1251637.62, 1252087.76, 1252537.9, 1252988.04, 1253438.18, 1253888.32,
1254338.46, 1254788.6, 1255238.74, 1255688.88, 1256139.02, 1256589.16,
1257039.3, 1257489.44, 1257939.58, 1258389.72, 1258839.86, 1259290
), tess = structure(list(type = "rect", window = structure(list(
type = "rectangle", xrange = c(2671317, 2694605), yrange = c(1236783,
1259290), units = structure(list(singular = "unit", plural = "units",
multiplier = 1), class = "unitname")), class = "owin"),
xgrid = c(2671317, 2671782.76, 2672248.52, 2672714.28, 2673180.04,
2673645.8, 2674111.56, 2674577.32, 2675043.08, 2675508.84,
2675974.6, 2676440.36, 2676906.12, 2677371.88, 2677837.64,
2678303.4, 2678769.16, 2679234.92, 2679700.68, 2680166.44,
2680632.2, 2681097.96, 2681563.72, 2682029.48, 2682495.24,
2682961, 2683426.76, 2683892.52, 2684358.28, 2684824.04,
2685289.8, 2685755.56, 2686221.32, 2686687.08, 2687152.84,
2687618.6, 2688084.36, 2688550.12, 2689015.88, 2689481.64,
2689947.4, 2690413.16, 2690878.92, 2691344.68, 2691810.44,
2692276.2, 2692741.96, 2693207.72, 2693673.48, 2694139.24,
2694605), ygrid = c(1236783, 1237233.14, 1237683.28, 1238133.42,
1238583.56, 1239033.7, 1239483.84, 1239933.98, 1240384.12,
1240834.26, 1241284.4, 1241734.54, 1242184.68, 1242634.82,
1243084.96, 1243535.1, 1243985.24, 1244435.38, 1244885.52,
1245335.66, 1245785.8, 1246235.94, 1246686.08, 1247136.22,
1247586.36, 1248036.5, 1248486.64, 1248936.78, 1249386.92,
1249837.06, 1250287.2, 1250737.34, 1251187.48, 1251637.62,
1252087.76, 1252537.9, 1252988.04, 1253438.18, 1253888.32,
1254338.46, 1254788.6, 1255238.74, 1255688.88, 1256139.02,
1256589.16, 1257039.3, 1257489.44, 1257939.58, 1258389.72,
1258839.86, 1259290), n = 2500), class = c("tess", "list"
)))
My goal is to either create a subset of all the rectangles that have a Freq above 100, or add a separate column with a binary classification if the row has a Freq above 100 or not.
My approach was to create a data.frame first and then the idea would be to change it back to a spatial data format. This is my unsuccessful approach:
Qdf <- as.data.frame(Q)
Qdf <- subset(Qdf, Qdf$Freq>100)
From here on I am unable to further display the data on a map.
Your help is very appreciated!
Did you start with a planar point pattern (ppp) and then create the
quadratcount from there? In that case I recommend you use pixellate to get
the counts directly in a raster format (im class in spatstat):
library(spatstat)
X <- bei
plot(X, main = "")
nx <- 10
ny <- 5
Xqc <- quadratcount(bei, nx = nx, ny = ny)
plot(Xqc, main = "")
Xim <- pixellate(X, dimyx = c(ny, nx))
plot(Xim , main = "")
plot(Xqc, add = TRUE)
Xim2 <- Xim[Xim>100, drop=FALSE] # If drop=TRUE vector of values is returned
plot(Xim2, main = "")
I'm not familiar with spatstat package. But, since your data are basically in a spatial raster grid, you could convert them to raster format and uselibrary(raster) for spatial operations like subsetting, reclassifying, and displaying on maps:
xr = attributes(Q)$xbreaks[c(1, dim(Q)[1]+1L)]
yr = attributes(Q)$ybreaks[c(1, dim(Q)[2]+1L)]
r = raster(matrix(Q, nrow(Q)), xmn=xr[1], xmx=xr[2], ymn=yr[1], ymx=yr[2])
plot(r)
Now we can see where the count is greater than 100
plot(r>100)
Or, see the values, only where they are greater than 100.
r100 = reclassify(r, cbind(-Inf, 100, NA), right=FALSE)
plot(r100)

Trouble with Error: Column `group` can't be modified because it's a grouping variable

I addressed this question in a previous post but because I did not get a satisfactory answer I've tried the following.
I've a dataset with 80-second intervals that I would like to transform into 240-second intervals. Here's a sample of it:
> head(dataraw)
GMT_DATE GMT_TIME ACTIVITY_X ACTIVITY_Y ACTIVITY_Z Vigilance Head-up Grazing Browsing Moving
1: 06/17/2018 09:36:00 78 38 87 0 35 0 35 1
2: 06/17/2018 09:37:20 18 17 25 0 46 0 0 26
3: 06/17/2018 09:38:40 7 4 8 0 69 0 0 0
4: 06/17/2018 09:40:00 4 0 4 0 70 0 0 0
5: 06/17/2018 09:41:20 11 8 14 0 29 0 0 11
6: 06/17/2018 09:42:40 27 20 34 0 0 58 0 0
Grooming Resting Fleeing Unknown End Total
1: 4 0 0 5 0 80
2: 8 0 0 0 0 80
3: 5 0 0 6 0 80
4: 10 0 0 0 0 80
5: 15 0 0 25 0 80
6: 10 0 0 12 0 80
However, note that some intervals are 160-seconds (rows 5 to 6), which I'm still not sure how to address that issue:
> head(dataraw[c(3626:3632),])
GMT_DATE GMT_TIME ACTIVITY_X ACTIVITY_Y ACTIVITY_Z Vigilance Head-up Grazing Browsing Moving
1: 06/20/2018 18:09:20 0 0 0 0 0 0 0 0
2: 06/20/2018 18:10:40 0 0 0 0 0 0 0 0
3: 06/20/2018 18:12:00 1 0 1 0 0 0 0 0
4: 06/20/2018 18:13:20 0 0 0 0 0 0 0 0
5: 06/20/2018 18:14:40 0 0 0 0 0 0 0 0
6: 06/20/2018 18:17:20 4 0 4 0 0 0 0 0
Grooming Resting Fleeing Unknown End Total
1: 0 0 0 0 80 80
2: 0 0 0 0 80 80
3: 0 0 0 0 80 80
4: 0 0 0 0 80 80
5: 0 0 0 0 80 80
6: 0 0 0 0 80 80
Anyways, I tried the script below for which I'm getting the error:
> library(dplyr)
> datarawnew<-dataraw %>%
+ tidyr::unite(datetime, GMT_DATE, GMT_TIME, sep = " ") %>%
+ mutate(datetime = as.POSIXct(datetime, format = "%m/%d/%Y %H:%M:%S"),
+ row = 1) %>%
+ group_by(group = cut(datetime, breaks = "4 mins")) %>%
+ summarise_at(-1, sum) %>%
+ mutate_at(vars(starts_with("ACTIVITY")), ~. /row) %>%
+ ungroup() %>%
+ select(-row)
Error in summarise_impl(.data, dots) :
Column `group` can't be modified because it's a grouping variable
Could anybody please let me know what am I doing wrong? I can upload a dput() sample below:
> dput(dataraw[c(1:250),])
structure(list(GMT_DATE = c("06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018"), GMT_TIME = c("09:36:00", "09:37:20",
"09:38:40", "09:40:00", "09:41:20", "09:42:40", "09:44:00", "09:45:20",
"09:46:40", "09:48:00", "09:49:20", "09:50:40", "09:52:00", "09:53:20",
"09:54:40", "09:56:00", "09:57:20", "09:58:40", "10:00:00", "10:01:20",
"10:02:40", "10:04:00", "10:05:20", "10:06:40", "10:08:00", "10:09:20",
"10:10:40", "10:12:00", "10:13:20", "10:14:40", "10:16:00", "10:17:20",
"10:18:40", "10:20:00", "10:21:20", "10:22:40", "10:24:00", "10:25:20",
"10:26:40", "10:28:00", "10:29:20", "10:30:40", "10:32:00", "10:33:20",
"10:34:40", "10:36:00", "10:37:20", "10:38:40", "10:40:00", "10:41:20",
"10:42:40", "10:44:00", "10:45:20", "10:46:40", "10:48:00", "10:49:20",
"10:50:40", "10:52:00", "10:53:20", "10:54:40", "10:56:00", "10:57:20",
"10:58:40", "11:00:00", "11:01:20", "11:02:40", "11:04:00", "11:05:20",
"11:06:40", "11:08:00", "11:09:20", "11:10:40", "11:12:00", "11:13:20",
"11:14:40", "11:16:00", "11:17:20", "11:18:40", "11:20:00", "11:21:20",
"11:22:40", "11:24:00", "11:25:20", "11:26:40", "11:28:00", "11:29:20",
"11:30:40", "11:32:00", "11:33:20", "11:34:40", "11:36:00", "11:37:20",
"11:38:40", "11:40:00", "11:41:20", "11:42:40", "11:44:00", "11:45:20",
"11:46:40", "11:48:00", "11:49:20", "11:50:40", "11:52:00", "11:53:20",
"11:54:40", "11:56:00", "11:57:20", "11:58:40", "12:00:00", "12:01:20",
"12:02:40", "12:04:00", "12:05:20", "12:06:40", "12:08:00", "12:09:20",
"12:10:40", "12:12:00", "12:13:20", "12:14:40", "12:16:00", "12:17:20",
"12:18:40", "12:20:00", "12:21:20", "12:22:40", "12:24:00", "12:25:20",
"12:26:40", "12:28:00", "12:29:20", "12:30:40", "12:32:00", "12:33:20",
"12:34:40", "12:36:00", "12:37:20", "12:38:40", "12:40:00", "12:41:20",
"12:42:40", "12:44:00", "12:45:20", "12:46:40", "12:48:00", "12:49:20",
"12:50:40", "12:52:00", "12:53:20", "12:54:40", "12:56:00", "12:57:20",
"12:58:40", "13:00:00", "13:01:20", "13:02:40", "13:04:00", "13:05:20",
"13:06:40", "13:08:00", "13:09:20", "13:10:40", "13:12:00", "13:13:20",
"13:14:40", "13:16:00", "13:17:20", "13:18:40", "13:20:00", "13:21:20",
"13:22:40", "13:24:00", "13:25:20", "13:26:40", "13:28:00", "13:29:20",
"13:30:40", "13:32:00", "13:33:20", "13:34:40", "13:36:00", "13:37:20",
"13:38:40", "13:40:00", "13:41:20", "13:42:40", "13:44:00", "13:45:20",
"13:46:40", "13:48:00", "13:49:20", "13:50:40", "13:52:00", "13:53:20",
"13:54:40", "13:56:00", "13:57:20", "13:58:40", "14:00:00", "14:01:20",
"14:02:40", "14:04:00", "14:05:20", "14:06:40", "14:08:00", "14:09:20",
"14:10:40", "14:12:00", "14:13:20", "14:14:40", "14:16:00", "14:17:20",
"14:18:40", "14:20:00", "14:21:20", "14:22:40", "14:24:00", "14:25:20",
"14:26:40", "14:28:00", "14:29:20", "14:30:40", "14:32:00", "14:33:20",
"14:34:40", "14:36:00", "14:37:20", "14:38:40", "14:40:00", "14:41:20",
"14:42:40", "14:44:00", "14:45:20", "14:46:40", "14:48:00", "14:49:20",
"14:50:40", "14:52:00", "14:53:20", "14:54:40", "14:56:00", "14:57:20",
"14:58:40", "15:00:00", "15:01:20", "15:02:40", "15:04:00", "15:05:20",
"15:06:40", "15:08:00"), ACTIVITY_X = c(78L, 18L, 7L, 4L, 11L,
27L, 19L, 23L, 21L, 19L, 24L, 25L, 13L, 15L, 31L, 52L, 71L, 141L,
103L, 59L, 43L, 85L, 129L, 81L, 106L, 86L, 129L, 82L, 67L, 145L,
120L, 95L, 97L, 139L, 160L, 147L, 83L, 102L, 84L, 90L, 92L, 84L,
95L, 121L, 84L, 58L, 72L, 72L, 52L, 65L, 83L, 57L, 61L, 72L,
82L, 88L, 116L, 125L, 126L, 79L, 49L, 51L, 77L, 84L, 99L, 96L,
90L, 72L, 74L, 61L, 86L, 71L, 52L, 24L, 52L, 55L, 53L, 37L, 49L,
57L, 58L, 59L, 45L, 53L, 72L, 49L, 60L, 77L, 79L, 93L, 110L,
76L, 108L, 63L, 78L, 78L, 83L, 66L, 40L, 30L, 75L, 29L, 30L,
37L, 39L, 38L, 41L, 48L, 16L, 58L, 75L, 81L, 85L, 64L, 51L, 31L,
33L, 76L, 65L, 76L, 63L, 75L, 59L, 60L, 44L, 54L, 51L, 68L, 75L,
93L, 82L, 83L, 86L, 79L, 67L, 59L, 94L, 75L, 47L, 28L, 66L, 58L,
53L, 34L, 31L, 40L, 35L, 45L, 33L, 47L, 42L, 24L, 25L, 26L, 21L,
26L, 30L, 47L, 34L, 28L, 31L, 48L, 33L, 45L, 33L, 41L, 40L, 44L,
53L, 25L, 38L, 27L, 44L, 96L, 42L, 55L, 49L, 44L, 46L, 45L, 51L,
58L, 36L, 27L, 35L, 53L, 44L, 44L, 60L, 29L, 36L, 38L, 39L, 36L,
37L, 32L, 23L, 35L, 46L, 58L, 63L, 67L, 166L, 123L, 44L, 53L,
68L, 43L, 48L, 61L, 48L, 65L, 54L, 69L, 67L, 62L, 51L, 49L, 41L,
42L, 39L, 58L, 40L, 52L, 46L, 38L, 48L, 28L, 32L, 48L, 42L, 39L,
90L, 108L, 44L, 40L, 22L, 38L, 22L, 45L, 32L, 27L, 23L, 13L,
53L, 32L, 45L, 62L, 55L, 48L), ACTIVITY_Y = c(38L, 17L, 4L, 0L,
8L, 20L, 11L, 11L, 8L, 13L, 16L, 23L, 4L, 8L, 21L, 46L, 105L,
133L, 131L, 64L, 34L, 76L, 94L, 51L, 80L, 58L, 69L, 47L, 57L,
108L, 102L, 80L, 71L, 127L, 135L, 114L, 116L, 131L, 100L, 77L,
131L, 127L, 72L, 114L, 87L, 54L, 97L, 88L, 43L, 45L, 84L, 62L,
91L, 87L, 114L, 94L, 76L, 97L, 81L, 155L, 49L, 72L, 89L, 125L,
113L, 63L, 66L, 78L, 82L, 44L, 96L, 53L, 47L, 20L, 35L, 42L,
46L, 31L, 38L, 45L, 37L, 42L, 34L, 28L, 86L, 55L, 42L, 62L, 63L,
113L, 95L, 131L, 215L, 79L, 90L, 43L, 42L, 54L, 47L, 24L, 96L,
31L, 34L, 24L, 46L, 36L, 42L, 59L, 13L, 73L, 73L, 94L, 109L,
89L, 28L, 26L, 38L, 105L, 60L, 129L, 48L, 59L, 81L, 67L, 51L,
36L, 81L, 154L, 74L, 80L, 81L, 79L, 83L, 57L, 47L, 62L, 75L,
57L, 43L, 33L, 66L, 58L, 81L, 20L, 16L, 27L, 25L, 34L, 15L, 30L,
31L, 9L, 24L, 18L, 19L, 22L, 21L, 63L, 33L, 15L, 15L, 43L, 25L,
28L, 23L, 30L, 21L, 24L, 40L, 18L, 35L, 16L, 37L, 120L, 27L,
45L, 42L, 33L, 45L, 36L, 32L, 36L, 35L, 22L, 24L, 31L, 38L, 32L,
46L, 21L, 22L, 20L, 22L, 21L, 25L, 22L, 18L, 22L, 26L, 43L, 83L,
103L, 239L, 165L, 49L, 47L, 41L, 27L, 33L, 36L, 26L, 46L, 25L,
36L, 55L, 42L, 41L, 39L, 16L, 25L, 22L, 43L, 28L, 36L, 30L, 19L,
19L, 13L, 16L, 41L, 37L, 117L, 132L, 45L, 45L, 23L, 19L, 29L,
19L, 55L, 43L, 38L, 15L, 11L, 52L, 28L, 32L, 45L, 71L, 53L),
ACTIVITY_Z = c(87L, 25L, 8L, 4L, 14L, 34L, 22L, 25L, 22L,
23L, 29L, 34L, 14L, 17L, 37L, 69L, 127L, 194L, 167L, 87L,
55L, 114L, 160L, 96L, 133L, 104L, 146L, 95L, 88L, 181L, 157L,
124L, 120L, 188L, 209L, 186L, 143L, 166L, 131L, 118L, 160L,
152L, 119L, 166L, 121L, 79L, 121L, 114L, 67L, 79L, 118L,
84L, 110L, 113L, 140L, 129L, 139L, 158L, 150L, 174L, 69L,
88L, 118L, 151L, 150L, 115L, 112L, 106L, 110L, 75L, 129L,
89L, 70L, 31L, 63L, 69L, 70L, 48L, 62L, 73L, 69L, 72L, 56L,
60L, 112L, 74L, 73L, 99L, 101L, 146L, 145L, 151L, 241L, 101L,
119L, 89L, 93L, 85L, 62L, 38L, 122L, 42L, 45L, 44L, 60L,
52L, 59L, 76L, 21L, 93L, 105L, 124L, 138L, 110L, 58L, 40L,
50L, 130L, 88L, 150L, 79L, 95L, 100L, 90L, 67L, 65L, 96L,
168L, 105L, 123L, 115L, 115L, 120L, 97L, 82L, 86L, 120L,
94L, 64L, 43L, 93L, 82L, 97L, 39L, 35L, 48L, 43L, 56L, 36L,
56L, 52L, 26L, 35L, 32L, 28L, 34L, 37L, 79L, 47L, 32L, 34L,
64L, 41L, 53L, 40L, 51L, 45L, 50L, 66L, 31L, 52L, 31L, 57L,
154L, 50L, 71L, 65L, 55L, 64L, 58L, 60L, 68L, 50L, 35L, 42L,
61L, 58L, 54L, 76L, 36L, 42L, 43L, 45L, 42L, 45L, 39L, 29L,
41L, 53L, 72L, 104L, 123L, 291L, 206L, 66L, 71L, 79L, 51L,
58L, 71L, 55L, 80L, 60L, 78L, 87L, 75L, 65L, 63L, 44L, 49L,
45L, 72L, 49L, 63L, 55L, 42L, 52L, 31L, 36L, 63L, 56L, 123L,
160L, 117L, 63L, 46L, 29L, 48L, 29L, 71L, 54L, 47L, 27L,
17L, 74L, 43L, 55L, 77L, 90L, 72L), Vigilance = c(0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
7L, 18L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0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 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 61L,
12L, 39L, 0L, 0L, 0L, 0L, 0L), End = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 31L, 80L, 80L, 80L, 39L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 37L, 19L, 0L, 0L, 0L, 0L, 0L, 0L, 58L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 19L, 0L, 0L, 0L, 0L, 69L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 39L, 0L, 0L, 0L, 0L, 41L, 80L, 80L, 80L, 39L, 0L
), Total = c(80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L)), row.names = c(NA, -250L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x0000000002631ef0>)
The following code you posted:
> dataraw %>%
+ tidyr::unite(datetime, GMT_DATE, GMT_TIME, sep = " ") %>%
+ mutate(datetime = as.POSIXct(datetime, format = "%m/%d/%Y %H:%M:%S"),
+ row = 1) %>%
+ group_by(group = cut(datetime, breaks = "4 mins")) %>%
+ summarise_at(-1, sum) %>%
+ mutate_at(vars(starts_with("ACTIVITY")), ~. /row) %>%
+ ungroup() %>%
+ select(-row)
never assigned this to a new data frame or over wrote the original data. I.e., you are missing:
newdataraw <- dataraw %>% ...
So, try running, e.g.,
newdataraw <- dataraw %>%
tidyr::unite(datetime, GMT_DATE, GMT_TIME, sep = " ") %>%
mutate(datetime = as.POSIXct(datetime, format = "%m/%d/%Y %H:%M:%S"),
row = 1) %>%
group_by(group = cut(datetime, breaks = "4 mins")) %>%
summarise_at(-1, sum) %>%
mutate_at(vars(starts_with("ACTIVITY")), ~. /row) %>%
ungroup() %>%
select(-row)
If that solves it, then you just have the typo, as mentioned above..

Aggregating time stamped data into four minute intervals with exceptions

I need to transform time-stamped data with 80-second intervals into 4-minute (240-second) intervals.
The two main challenges I have is the large number of columns, and the fact that a few of the intervals are not 80-second, that's why I need help. Below is a head() sample of my dataset:
> head(dataraw)
GMT_DATE GMT_TIME ACTIVITY_X ACTIVITY_Y ACTIVITY_Z Vigilance Head-up Grazing Browsing Moving
1: 06/17/2018 09:36:00 78 38 87 0 35 0 35 1
2: 06/17/2018 09:37:20 18 17 25 0 46 0 0 26
3: 06/17/2018 09:38:40 7 4 8 0 69 0 0 0
4: 06/17/2018 09:40:00 4 0 4 0 70 0 0 0
5: 06/17/2018 09:41:20 11 8 14 0 29 0 0 11
6: 06/17/2018 09:42:40 27 20 34 0 0 58 0 0
Grooming Resting Fleeing Unknown End Total
1: 4 0 0 5 0 80
2: 8 0 0 0 0 80
3: 5 0 0 6 0 80
4: 10 0 0 0 0 80
5: 15 0 0 25 0 80
6: 10 0 0 12 0 80
As you can see, time-stamps have been taken every 80-seconds, although some of the time-stamps are 160-seconds as seen below on rows 5 and 6:
> head(dataraw[c(3626:3632),])
GMT_DATE GMT_TIME ACTIVITY_X ACTIVITY_Y ACTIVITY_Z Vigilance Head-up Grazing Browsing Moving
1: 06/20/2018 18:09:20 0 0 0 0 0 0 0 0
2: 06/20/2018 18:10:40 0 0 0 0 0 0 0 0
3: 06/20/2018 18:12:00 1 0 1 0 0 0 0 0
4: 06/20/2018 18:13:20 0 0 0 0 0 0 0 0
5: 06/20/2018 18:14:40 0 0 0 0 0 0 0 0
6: 06/20/2018 18:17:20 4 0 4 0 0 0 0 0
Grooming Resting Fleeing Unknown End Total
1: 0 0 0 0 80 80
2: 0 0 0 0 80 80
3: 0 0 0 0 80 80
4: 0 0 0 0 80 80
5: 0 0 0 0 80 80
6: 0 0 0 0 80 80
Hence, the best I can do is to aggregate by time-stamps having 00 in their seconds format. That is going from 09:36:00, to 09:40:00, to 09:44:00 etc.
How can I do this?
As for the values in columns ACTIVITY_X, ACTIVITY_Y and ACTIVITY_Z, they should be averaged when merged. For the rest of the columns, values can be summed when aggregated. Column Total will then have 240 for 4-minutes intervals (240 seconds).
I hope somebody can at least set me on the right track. Any input is truly appreciated!
> dput(dataraw[(1:280),])
structure(list(GMT_DATE = c("06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018", "06/17/2018",
"06/17/2018", "06/17/2018"), GMT_TIME = c("09:36:00", "09:37:20",
"09:38:40", "09:40:00", "09:41:20", "09:42:40", "09:44:00", "09:45:20",
"09:46:40", "09:48:00", "09:49:20", "09:50:40", "09:52:00", "09:53:20",
"09:54:40", "09:56:00", "09:57:20", "09:58:40", "10:00:00", "10:01:20",
"10:02:40", "10:04:00", "10:05:20", "10:06:40", "10:08:00", "10:09:20",
"10:10:40", "10:12:00", "10:13:20", "10:14:40", "10:16:00", "10:17:20",
"10:18:40", "10:20:00", "10:21:20", "10:22:40", "10:24:00", "10:25:20",
"10:26:40", "10:28:00", "10:29:20", "10:30:40", "10:32:00", "10:33:20",
"10:34:40", "10:36:00", "10:37:20", "10:38:40", "10:40:00", "10:41:20",
"10:42:40", "10:44:00", "10:45:20", "10:46:40", "10:48:00", "10:49:20",
"10:50:40", "10:52:00", "10:53:20", "10:54:40", "10:56:00", "10:57:20",
"10:58:40", "11:00:00", "11:01:20", "11:02:40", "11:04:00", "11:05:20",
"11:06:40", "11:08:00", "11:09:20", "11:10:40", "11:12:00", "11:13:20",
"11:14:40", "11:16:00", "11:17:20", "11:18:40", "11:20:00", "11:21:20",
"11:22:40", "11:24:00", "11:25:20", "11:26:40", "11:28:00", "11:29:20",
"11:30:40", "11:32:00", "11:33:20", "11:34:40", "11:36:00", "11:37:20",
"11:38:40", "11:40:00", "11:41:20", "11:42:40", "11:44:00", "11:45:20",
"11:46:40", "11:48:00", "11:49:20", "11:50:40", "11:52:00", "11:53:20",
"11:54:40", "11:56:00", "11:57:20", "11:58:40", "12:00:00", "12:01:20",
"12:02:40", "12:04:00", "12:05:20", "12:06:40", "12:08:00", "12:09:20",
"12:10:40", "12:12:00", "12:13:20", "12:14:40", "12:16:00", "12:17:20",
"12:18:40", "12:20:00", "12:21:20", "12:22:40", "12:24:00", "12:25:20",
"12:26:40", "12:28:00", "12:29:20", "12:30:40", "12:32:00", "12:33:20",
"12:34:40", "12:36:00", "12:37:20", "12:38:40", "12:40:00", "12:41:20",
"12:42:40", "12:44:00", "12:45:20", "12:46:40", "12:48:00", "12:49:20",
"12:50:40", "12:52:00", "12:53:20", "12:54:40", "12:56:00", "12:57:20",
"12:58:40", "13:00:00", "13:01:20", "13:02:40", "13:04:00", "13:05:20",
"13:06:40", "13:08:00", "13:09:20", "13:10:40", "13:12:00", "13:13:20",
"13:14:40", "13:16:00", "13:17:20", "13:18:40", "13:20:00", "13:21:20",
"13:22:40", "13:24:00", "13:25:20", "13:26:40", "13:28:00", "13:29:20",
"13:30:40", "13:32:00", "13:33:20", "13:34:40", "13:36:00", "13:37:20",
"13:38:40", "13:40:00", "13:41:20", "13:42:40", "13:44:00", "13:45:20",
"13:46:40", "13:48:00", "13:49:20", "13:50:40", "13:52:00", "13:53:20",
"13:54:40", "13:56:00", "13:57:20", "13:58:40", "14:00:00", "14:01:20",
"14:02:40", "14:04:00", "14:05:20", "14:06:40", "14:08:00", "14:09:20",
"14:10:40", "14:12:00", "14:13:20", "14:14:40", "14:16:00", "14:17:20",
"14:18:40", "14:20:00", "14:21:20", "14:22:40", "14:24:00", "14:25:20",
"14:26:40", "14:28:00", "14:29:20", "14:30:40", "14:32:00", "14:33:20",
"14:34:40", "14:36:00", "14:37:20", "14:38:40", "14:40:00", "14:41:20",
"14:42:40", "14:44:00", "14:45:20", "14:46:40", "14:48:00", "14:49:20",
"14:50:40", "14:52:00", "14:53:20", "14:54:40", "14:56:00", "14:57:20",
"14:58:40", "15:00:00", "15:01:20", "15:02:40", "15:04:00", "15:05:20",
"15:06:40", "15:08:00", "15:09:20", "15:10:40", "15:12:00", "15:13:20",
"15:14:40", "15:16:00", "15:17:20", "15:18:40", "15:20:00", "15:21:20",
"15:22:40", "15:24:00", "15:25:20", "15:26:40", "15:28:00", "15:29:20",
"15:30:40", "15:32:00", "15:33:20", "15:34:40", "15:36:00", "15:37:20",
"15:38:40", "15:40:00", "15:41:20", "15:42:40", "15:44:00", "15:45:20",
"15:46:40", "15:48:00"), ACTIVITY_X = c(78L, 18L, 7L, 4L, 11L,
27L, 19L, 23L, 21L, 19L, 24L, 25L, 13L, 15L, 31L, 52L, 71L, 141L,
103L, 59L, 43L, 85L, 129L, 81L, 106L, 86L, 129L, 82L, 67L, 145L,
120L, 95L, 97L, 139L, 160L, 147L, 83L, 102L, 84L, 90L, 92L, 84L,
95L, 121L, 84L, 58L, 72L, 72L, 52L, 65L, 83L, 57L, 61L, 72L,
82L, 88L, 116L, 125L, 126L, 79L, 49L, 51L, 77L, 84L, 99L, 96L,
90L, 72L, 74L, 61L, 86L, 71L, 52L, 24L, 52L, 55L, 53L, 37L, 49L,
57L, 58L, 59L, 45L, 53L, 72L, 49L, 60L, 77L, 79L, 93L, 110L,
76L, 108L, 63L, 78L, 78L, 83L, 66L, 40L, 30L, 75L, 29L, 30L,
37L, 39L, 38L, 41L, 48L, 16L, 58L, 75L, 81L, 85L, 64L, 51L, 31L,
33L, 76L, 65L, 76L, 63L, 75L, 59L, 60L, 44L, 54L, 51L, 68L, 75L,
93L, 82L, 83L, 86L, 79L, 67L, 59L, 94L, 75L, 47L, 28L, 66L, 58L,
53L, 34L, 31L, 40L, 35L, 45L, 33L, 47L, 42L, 24L, 25L, 26L, 21L,
26L, 30L, 47L, 34L, 28L, 31L, 48L, 33L, 45L, 33L, 41L, 40L, 44L,
53L, 25L, 38L, 27L, 44L, 96L, 42L, 55L, 49L, 44L, 46L, 45L, 51L,
58L, 36L, 27L, 35L, 53L, 44L, 44L, 60L, 29L, 36L, 38L, 39L, 36L,
37L, 32L, 23L, 35L, 46L, 58L, 63L, 67L, 166L, 123L, 44L, 53L,
68L, 43L, 48L, 61L, 48L, 65L, 54L, 69L, 67L, 62L, 51L, 49L, 41L,
42L, 39L, 58L, 40L, 52L, 46L, 38L, 48L, 28L, 32L, 48L, 42L, 39L,
90L, 108L, 44L, 40L, 22L, 38L, 22L, 45L, 32L, 27L, 23L, 13L,
53L, 32L, 45L, 62L, 55L, 48L, 10L, 2L, 11L, 29L, 52L, 18L, 17L,
17L, 10L, 1L, 33L, 19L, 22L, 10L, 23L, 46L, 81L, 115L, 97L, 111L,
75L, 44L, 75L, 86L, 35L, 32L, 24L, 18L, 20L, 29L), ACTIVITY_Y = c(38L,
17L, 4L, 0L, 8L, 20L, 11L, 11L, 8L, 13L, 16L, 23L, 4L, 8L, 21L,
46L, 105L, 133L, 131L, 64L, 34L, 76L, 94L, 51L, 80L, 58L, 69L,
47L, 57L, 108L, 102L, 80L, 71L, 127L, 135L, 114L, 116L, 131L,
100L, 77L, 131L, 127L, 72L, 114L, 87L, 54L, 97L, 88L, 43L, 45L,
84L, 62L, 91L, 87L, 114L, 94L, 76L, 97L, 81L, 155L, 49L, 72L,
89L, 125L, 113L, 63L, 66L, 78L, 82L, 44L, 96L, 53L, 47L, 20L,
35L, 42L, 46L, 31L, 38L, 45L, 37L, 42L, 34L, 28L, 86L, 55L, 42L,
62L, 63L, 113L, 95L, 131L, 215L, 79L, 90L, 43L, 42L, 54L, 47L,
24L, 96L, 31L, 34L, 24L, 46L, 36L, 42L, 59L, 13L, 73L, 73L, 94L,
109L, 89L, 28L, 26L, 38L, 105L, 60L, 129L, 48L, 59L, 81L, 67L,
51L, 36L, 81L, 154L, 74L, 80L, 81L, 79L, 83L, 57L, 47L, 62L,
75L, 57L, 43L, 33L, 66L, 58L, 81L, 20L, 16L, 27L, 25L, 34L, 15L,
30L, 31L, 9L, 24L, 18L, 19L, 22L, 21L, 63L, 33L, 15L, 15L, 43L,
25L, 28L, 23L, 30L, 21L, 24L, 40L, 18L, 35L, 16L, 37L, 120L,
27L, 45L, 42L, 33L, 45L, 36L, 32L, 36L, 35L, 22L, 24L, 31L, 38L,
32L, 46L, 21L, 22L, 20L, 22L, 21L, 25L, 22L, 18L, 22L, 26L, 43L,
83L, 103L, 239L, 165L, 49L, 47L, 41L, 27L, 33L, 36L, 26L, 46L,
25L, 36L, 55L, 42L, 41L, 39L, 16L, 25L, 22L, 43L, 28L, 36L, 30L,
19L, 19L, 13L, 16L, 41L, 37L, 117L, 132L, 45L, 45L, 23L, 19L,
29L, 19L, 55L, 43L, 38L, 15L, 11L, 52L, 28L, 32L, 45L, 71L, 53L,
4L, 1L, 8L, 17L, 42L, 12L, 9L, 6L, 5L, 0L, 30L, 16L, 16L, 19L,
51L, 68L, 111L, 108L, 105L, 97L, 69L, 22L, 54L, 80L, 22L, 19L,
20L, 29L, 15L, 22L), ACTIVITY_Z = c(87L, 25L, 8L, 4L, 14L, 34L,
22L, 25L, 22L, 23L, 29L, 34L, 14L, 17L, 37L, 69L, 127L, 194L,
167L, 87L, 55L, 114L, 160L, 96L, 133L, 104L, 146L, 95L, 88L,
181L, 157L, 124L, 120L, 188L, 209L, 186L, 143L, 166L, 131L, 118L,
160L, 152L, 119L, 166L, 121L, 79L, 121L, 114L, 67L, 79L, 118L,
84L, 110L, 113L, 140L, 129L, 139L, 158L, 150L, 174L, 69L, 88L,
118L, 151L, 150L, 115L, 112L, 106L, 110L, 75L, 129L, 89L, 70L,
31L, 63L, 69L, 70L, 48L, 62L, 73L, 69L, 72L, 56L, 60L, 112L,
74L, 73L, 99L, 101L, 146L, 145L, 151L, 241L, 101L, 119L, 89L,
93L, 85L, 62L, 38L, 122L, 42L, 45L, 44L, 60L, 52L, 59L, 76L,
21L, 93L, 105L, 124L, 138L, 110L, 58L, 40L, 50L, 130L, 88L, 150L,
79L, 95L, 100L, 90L, 67L, 65L, 96L, 168L, 105L, 123L, 115L, 115L,
120L, 97L, 82L, 86L, 120L, 94L, 64L, 43L, 93L, 82L, 97L, 39L,
35L, 48L, 43L, 56L, 36L, 56L, 52L, 26L, 35L, 32L, 28L, 34L, 37L,
79L, 47L, 32L, 34L, 64L, 41L, 53L, 40L, 51L, 45L, 50L, 66L, 31L,
52L, 31L, 57L, 154L, 50L, 71L, 65L, 55L, 64L, 58L, 60L, 68L,
50L, 35L, 42L, 61L, 58L, 54L, 76L, 36L, 42L, 43L, 45L, 42L, 45L,
39L, 29L, 41L, 53L, 72L, 104L, 123L, 291L, 206L, 66L, 71L, 79L,
51L, 58L, 71L, 55L, 80L, 60L, 78L, 87L, 75L, 65L, 63L, 44L, 49L,
45L, 72L, 49L, 63L, 55L, 42L, 52L, 31L, 36L, 63L, 56L, 123L,
160L, 117L, 63L, 46L, 29L, 48L, 29L, 71L, 54L, 47L, 27L, 17L,
74L, 43L, 55L, 77L, 90L, 72L, 11L, 2L, 14L, 34L, 67L, 22L, 19L,
18L, 11L, 1L, 45L, 25L, 27L, 21L, 56L, 82L, 137L, 158L, 143L,
147L, 102L, 49L, 92L, 117L, 41L, 37L, 31L, 34L, 25L, 36L), Vigilance = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
7L, 18L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L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0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 61L, 12L, 39L, 0L, 0L, 0L, 0L, 0L, 0L,
8L, 1L, 0L, 0L, 6L, 0L, 12L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), End = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 31L, 80L,
80L, 80L, 39L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 37L, 19L,
0L, 0L, 0L, 0L, 0L, 0L, 58L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 19L, 0L, 0L, 0L, 0L, 69L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 39L, 0L, 0L, 0L,
0L, 41L, 80L, 80L, 80L, 39L, 0L, 0L, 0L, 79L, 80L, 39L, 14L,
59L, 34L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 39L, 0L
), Total = c(80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L)), row.names = c(NA, -280L
), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000000006b01ef0>)
I would generate table with all possible times (without seconds, for example), where second column is group index, then do left_join from dplyr to the original table, at the end aggregate by this artificial index.
Btw, it's very convenient to do so, if you plan to make a plot in ggplot, you just write aes(x=.., y=.., col=index)
First, make standard POSIXct format from your columns GMT_DATE, GMT_TIME
then
time_seq_by_seconds = seq(as.POSIXct("2017-06-17 09:36:00"), as.POSIXct("2017-06-24 10:04:00"), 1)
number_of_groups = round(length(time_seq_by_seconds) / 80) +1
groups = do.call(c, lapply(1:number_of_groups, function(x){ rep(x,80)} ))
groups = groups[1:length(time_seq_by_seconds)]
indexed = as.data.frame(cbind(as.character(time_seq_by_seconds), groups))
colnames(indexed) = c("datetime","group")
library(dplyr)
joined = left_join(dataraw, indexed, by = c("GMT_DATETIME" = "datetime"))
Instead of using any hacky way of dealing with date-time treat them as POSIXct objects. We can combine GMT_DATE and GMT_TIME into one datetime column and convert them to actual date time objects. We can now create groups of 4 minute interval each using cut and then sum them all together. I created an extra column row with value 1 which can be later used to calculate average of "ACTIVITY" columns.
library(dplyr)
dataraw %>%
tidyr::unite(datetime, GMT_DATE, GMT_TIME, sep = " ") %>%
mutate(datetime = as.POSIXct(datetime, format = "%m/%d/%Y %H:%M:%S"),
row = 1) %>%
group_by(group = cut(datetime, breaks = "4 mins")) %>%
summarise_at(-1, sum) %>%
mutate_at(vars(starts_with("ACTIVITY")), ~. /row) %>%
ungroup() %>%
select(-row)
# A tibble: 94 x 15
# group ACTIVITY_X ACTIVITY_Y ACTIVITY_Z Vigilance `Head-up` Grazing Browsing..
# <fct> <dbl> <dbl> <dbl> <int> <int> <int> <int>
# 1 2018… 34.3 19.7 40 0 150 0 35...
# 2 2018… 14 9.33 17.3 0 99 58 0...
# 3 2018… 21 10 23 0 8 205 0...
# 4 2018… 22.7 17.3 28.7 0 0 38 0...
# 5 2018… 19.7 11 22.7 0 41 0 0...
# 6 2018… 88 94.7 130 7 225 0 0...
# 7 2018… 68.3 76.3 103 18 199 0 0...
# 8 2018… 98.3 73.7 123. 0 38 63 0...
# 9 2018… 107 69 128. 0 3 164 0...
#10 2018… 98 70.7 121. 0 12 144 21...
# … with 84 more rows, and 3 more variables: Unknown <int>, End <int>, Total <int>

Plot visreg over an boxplot (GLM with binominal predictor)

I fitted some GLMs with a binominal predictor and would like to plot them with visreg. I usually plot the raw data with par(new=T) as well for better clarity. I don't really like the normal outcome here (x-axis 0-1 in 0.2 steps, a lot of data points just at 0 and 1) and was thinking about plotting the visreg over boxplot since they look much better with binominal data. However, I can't get the two plots to align since there are always two different "starts" and "ends" in the plot. How can I make it so that the visreg line starts at the "No" and ends at the "Yes" of the boxplot?
fit <- glm (Cov.herb ~ Fire, family=gaussian, data=data)
boxplot(data$Cov.herb ~ data$Fire, ylim=c(0,100), axes=F, ylab="Herb cover [%]", xlab="Fire")
axis(1, xaxp=c(1,2,1), xaxt="n")
mtext(text=c("No","Yes"),side=1,line=0.5,at=c(1,2))
axis(2, las=1)
box()
par(new=T)
visreg(fit, scale = "response", type="conditional",line=list(col="red", lwd=1), ylim=c(0,100), xlim=c(0,1), rug=F, axes=F, ann=F)
example plot
Cheers,
Alex
data:
structure(list(Cov.herb = c(40L, 80L, 30L, 2L, 40L, 8L, 5L, 5L,
20L, 45L, 55L, 55L, 35L, 40L, 65L, 70L, 2L, 15L, 1L, 1L, 1L,
25L, 10L, 1L, 10L, 5L, 5L, 15L, 10L, 5L, 15L, 5L, 5L, 35L, 1L,
1L, 35L, 1L, 10L, 5L, 5L, 10L, 5L, 10L, 10L, 20L, 10L, 0L, 3L,
1L, 2L, 4L, 1L, 10L, 30L, 10L, 1L, 2L, 0L, 15L, 25L, 50L, 15L,
35L, 30L, 5L, 5L, 1L, 1L, 1L, 10L, 0L, 0L, 5L, 2L, 1L, 10L, 0L,
2L, 1L, 1L, 5L, 1L, 15L, 1L, 1L, 1L, 0L, 5L, 25L, 3L, 0L, 0L,
1L, 0L, 0L, 0L, 0L, 3L, 1L, 1L, 0L, 5L, 1L, 1L, 1L, 1L, 7L, 1L,
1L, 1L, 1L, 5L, 0L, 2L, 3L, 5L, 3L, 1L, 1L, 2L, 0L, 2L, 0L, 10L,
1L, 20L, 3L, 5L, 20L, 3L, 20L, 5L, 10L, 15L, 30L, 0L, 20L, 45L,
1L, 1L, 2L, 1L, 3L, 0L, 5L, 0L, 35L, 1L, 5L, 25L, 0L, 0L, 40L,
3L, 15L, 10L, 3L, 50L, 30L, 10L, 1L, 0L, 5L, 10L, 10L, 2L, 2L,
5L, 1L, 2L, 1L, 1L, 0L, 0L, 1L, 2L, 5L, 15L, 0L, 1L, 1L, 1L,
1L, 0L, 1L, 5L, 1L, 5L, 35L, 1L, 0L, 1L, 0L, 5L, 1L, 1L, 3L,
15L, 1L, 3L, 1L, 0L, 0L, 0L, 15L, 0L, 1L, 1L, 3L, 35L, 80L, 10L,
2L, 10L, 3L, 3L, 2L, 10L, 50L, 20L, 40L, 2L, 40L, 45L, 25L, 5L,
25L, 50L, 35L, 15L, 45L, 10L, 5L, 15L, 2L, 30L, 2L, 3L, 15L,
5L, 45L, 35L, 20L, 70L, 20L, 10L, 30L, 25L, 8L, 4L, 45L, 60L,
35L, 5L, 40L, 30L, 0L, 30L, 3L, 4L, 25L, 15L, 10L, 15L, 25L,
20L, 7L, 25L, 25L, 40L, 35L, 30L, 40L, 25L, 50L, 30L, 25L, 60L,
15L, 25L, 25L, 50L, 30L, 20L, 2L, 3L, 20L, 25L, 35L, 30L, 10L,
15L, 65L, 10L, 20L, 20L, 2L, 7L, 20L, 25L, 30L, 30L, 9L, 20L,
40L, 7L, 20L, 15L, 15L, 30L, 20L, 35L, 8L, 40L, 20L, 3L, 55L,
35L, 10L, 10L, 65L, 20L, 35L, 60L, 45L, 20L, 10L, 35L, 15L, 20L,
15L, 40L, 10L, 10L, 60L, 60L, 40L, 10L, 10L, 25L, 8L, 20L, 40L,
15L, 25L, 5L, 20L, 20L, 20L, 25L, 30L, 35L, 20L, 110L, 50L, 20L,
20L, 10L, 45L, 25L, 20L, 55L, 10L, 5L, 15L, 15L, 1L, 10L, 15L,
15L, 10L, 30L, 20L, 40L, 55L, 55L, 20L, 30L, 10L, 50L, 40L, 5L,
15L, 10L, 30L, 15L, 20L, 5L, 45L, 50L, 25L, 45L, 30L, 7L, 25L,
30L, 5L, 7L, 50L, 60L, 50L, 10L, 30L, 50L, 15L, 15L, 30L, 15L,
25L, 40L, 10L, 2L, 60L, 20L, 65L, 5L, 15L, 3L, 15L, 40L, 50L,
45L, 30L, 5L, 45L, 15L, 25L, 65L, 15L, 50L, 55L, 30L, 10L, 35L,
15L, 20L, 20L, 10L, 20L, 15L, 45L, 40L, 10L, 7L, 25L, 20L, 60L,
4L, 7L, 40L, 60L, 50L, 50L, 10L, 50L, 5L, 10L, 50L, 20L, 40L,
20L, 25L, 25L, 35L, 10L, 2L, 15L, 60L, 25L, 30L, 20L, 25L, 10L,
10L, 20L, 40L, 40L, 45L, 10L, 35L, 60L, 50L, 10L, 40L, 50L, 25L,
20L, 25L, 25L, 45L, 20L, 30L, 65L, 30L, 35L, 40L, 25L, 15L, 10L,
50L, 25L, 45L, 40L, 20L, 5L, 65L, 5L, 10L, 15L, 7L, 20L, 45L,
15L, 5L, 20L, 20L, 20L, 50L, 15L, 20L, 30L, 25L, 45L, 45L, 35L,
40L, 45L, 4L, 10L, 20L, 20L, 30L, 15L, 30L, 50L, 35L, 45L, 25L,
25L, 10L, 5L, 30L, 30L, 10L, 70L, 25L, 25L, 7L, 20L, 5L, 20L,
8L, 15L, 10L, 20L, 10L, 7L, 15L, 15L, 40L, 50L, 15L, 20L, 8L,
45L, 40L, 15L, 25L, 40L, 20L, 35L, 40L, 70L, 20L, 20L, 40L, 5L,
20L, 7L, 40L, 10L, 5L, 45L, 20L, 10L, 20L, 20L, 45L, 15L, 7L,
30L, 30L, 35L, 10L, 20L, 5L, 15L, 35L, 40L, 40L, 10L, 5L, 15L,
70L, 20L, 85L, 15L, 7L, 55L, 55L, 5L, 20L, 25L, 5L, 30L, 20L,
8L, 30L, 40L, 25L, 10L, 5L, 30L, 10L, 5L, 10L, 35L, 2L, 10L,
10L, 10L, 90L, 45L, 60L, 7L, 1L, 15L), Fire = c(0L, 1L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L,
1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0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L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("Cov.herb",
"Fire"), class = "data.frame", row.names = c(2L, 3L, 4L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 43L, 44L, 45L, 46L, 47L,
48L, 49L, 50L, 51L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 87L, 88L, 89L, 90L,
91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L,
103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L,
114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L,
125L, 126L, 153L, 154L, 155L, 161L, 162L, 163L, 164L, 165L, 166L,
167L, 169L, 170L, 171L, 173L, 174L, 175L, 176L, 177L, 178L, 179L,
180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L,
191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L, 201L,
202L, 203L, 204L, 205L, 206L, 207L, 209L, 211L, 213L, 214L, 215L,
216L, 217L, 218L, 219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L,
227L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L,
238L, 239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L,
249L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L,
260L, 261L, 262L, 263L, 269L, 270L, 274L, 275L, 276L, 277L, 279L,
280L, 281L, 282L, 283L, 284L, 285L, 286L, 287L, 288L, 289L, 290L,
291L, 292L, 293L, 294L, 295L, 296L, 297L, 298L, 299L, 300L, 301L,
302L, 303L, 304L, 305L, 306L, 307L, 308L, 309L, 310L, 311L, 312L,
313L, 314L, 315L, 316L, 317L, 318L, 319L, 320L, 321L, 322L, 323L,
324L, 325L, 326L, 327L, 328L, 329L, 330L, 331L, 332L, 333L, 334L,
335L, 336L, 337L, 338L, 339L, 340L, 341L, 342L, 343L, 344L, 345L,
346L, 347L, 349L, 350L, 351L, 352L, 353L, 354L, 355L, 356L, 357L,
358L, 359L, 360L, 361L, 362L, 363L, 364L, 365L, 366L, 367L, 368L,
369L, 370L, 371L, 372L, 373L, 374L, 375L, 376L, 377L, 378L, 380L,
381L, 382L, 383L, 384L, 385L, 386L, 387L, 388L, 389L, 390L, 391L,
392L, 393L, 394L, 395L, 396L, 397L, 398L, 399L, 400L, 401L, 402L,
403L, 404L, 405L, 406L, 407L, 408L, 409L, 410L, 411L, 412L, 413L,
414L, 415L, 416L, 417L, 418L, 419L, 420L, 421L, 422L, 423L, 424L,
425L, 426L, 427L, 428L, 429L, 430L, 431L, 432L, 433L, 434L, 435L,
436L, 437L, 438L, 439L, 440L, 441L, 443L, 444L, 445L, 446L, 447L,
448L, 449L, 450L, 451L, 453L, 454L, 455L, 457L, 458L, 459L, 460L,
461L, 463L, 464L, 465L, 466L, 467L, 468L, 469L, 470L, 471L, 472L,
473L, 474L, 475L, 476L, 477L, 478L, 479L, 480L, 481L, 482L, 483L,
484L, 485L, 486L, 487L, 488L, 489L, 490L, 491L, 492L, 493L, 494L,
495L, 496L, 497L, 498L, 499L, 500L, 501L, 502L, 503L, 504L, 505L,
506L, 507L, 508L, 509L, 510L, 511L, 512L, 513L, 514L, 515L, 516L,
517L, 518L, 519L, 520L, 521L, 522L, 523L, 524L, 525L, 526L, 527L,
528L, 529L, 530L, 531L, 532L, 533L, 534L, 535L, 536L, 537L, 538L,
539L, 540L, 541L, 542L, 543L, 544L, 545L, 546L, 547L, 548L, 549L,
551L, 552L, 553L, 554L, 555L, 556L, 557L, 558L, 559L, 560L, 561L,
562L, 563L, 564L, 565L, 566L, 567L, 568L, 569L, 570L, 571L, 572L,
573L, 574L, 575L, 576L, 577L, 578L, 579L, 580L, 581L, 582L, 583L,
584L, 585L, 587L, 588L, 589L, 590L, 591L, 592L, 593L, 594L, 595L,
596L, 597L, 598L, 599L, 600L, 601L, 602L, 603L, 604L, 605L, 606L,
607L, 608L, 609L, 610L, 611L, 612L, 613L, 614L, 615L, 616L, 617L,
618L, 619L, 620L, 621L, 622L, 623L, 624L, 625L, 626L, 628L, 629L,
631L, 632L, 633L, 634L, 635L, 636L, 637L, 638L, 639L, 640L, 641L,
642L, 643L, 644L, 645L, 646L, 648L, 649L, 650L, 651L, 652L, 653L,
654L, 655L, 656L, 657L, 658L, 659L, 660L, 661L, 662L, 663L, 664L,
665L, 666L, 667L, 668L, 669L, 670L, 671L, 672L, 673L, 674L, 675L,
676L, 677L, 678L, 679L, 680L, 682L, 683L, 684L, 685L, 686L, 687L,
689L, 690L, 691L, 692L, 693L, 694L, 697L, 698L, 699L, 700L, 701L,
702L, 704L, 705L, 706L, 707L))
So, my point was that doing it this way would give you more flexibility with your plotting. For example,
# Fit model
fit <- glm (Cov.herb ~ Fire, family=gaussian, data=data)
# Get model data for plotting
vis.out <- visreg(fit, scale = "response", plot = FALSE)
# Load library
library(ggplot2)
# Create plot
p <- ggplot(data = data)
p <- p + geom_boxplot(aes(x = as.factor(Fire), y = Cov.herb, fill = as.factor(Fire)), alpha = 0.3, outlier.alpha = 1)
p <- p + xlab("Fire") + ylab("Herb cover [%]")
p <- p + geom_ribbon(data = vis.out$fit, aes(x = Fire + 1, ymin = visregLwr, ymax = visregUpr), fill = "lightgrey")
p <- p + geom_line(data = vis.out$fit, aes(x = Fire + 1, y = visregFit), colour = "salmon", size = 1.25)
p <- p + scale_x_discrete(labels = c("No", "Yes"))
p <- p + theme(legend.position = "none")
print(p)
gives,
Is that the sort of thing you're looking for? (You could also add all the data points using geom_point to plot on top of the boxes. I think that usually looks pretty cool.)

Resources