Hello, I have more of a data question here.
I have been measuring size of animals (mussels). Once per year (2016, 2017, 2019, 2021, and 2022). Length = l and Width = w. I am trying to measure growth rates for length and width.
Should I mutate a new column (see my code below) for each year? This seems clunky.
Should I convert these data from wide to long?
Also, there are a lot of missing data because the animals go missing. And I add new animals each year to the dataset. Is this the best data structure for this?
A bit of my code with what I am trying to do (plot initial length versus growth rate):
mussels$animal <- as.factor(mussels$animal)
#> Error in is.factor(x): object 'mussels' not found
mussels <- mussels %>%
mutate(growth_2017 = (l_2017) -(l_2016))
#> Error in mussels %>% mutate(growth_2017 = (l_2017) - (l_2016)): could not find function "%>%"
plot1 <- mussels %>%
ggplot(aes(x = l_2016, y = growth_2017)) +
geom_point()
#> Error in mussels %>% ggplot(aes(x = l_2016, y = growth_2017)): could not find function "%>%"
plot1
#> Error in eval(expr, envir, enclos): object 'plot1' not found
Created on 2022-07-06 by the reprex package (v2.0.1)
Some of my data (hopefully Reprexed, correctly):
mussels2<- tibble::tribble(
~animal, ~l_2016, ~w_2016, ~l_2017, ~w_2017, ~l_2019, ~w_2019, ~l_2021, ~w_2021, ~l_2022, ~w_2022,
1L, 77.4, 23.6, 77.3, 23.5, 77.27, 39.87, NA, NA, NA, NA,
2L, 78, 27.5, 79, 27.4, 79.37, 45, NA, NA, NA, NA,
3L, 77.6, 21.7, 72.9, 23.6, 72.87, 37.5, NA, NA, NA, NA,
4L, 72.9, 23.2, 77.3, 21.5, 77.15, 38.5, NA, NA, NA, NA,
5L, 91.2, 30.4, 90.3, 30.9, 90.44, 51.4, NA, NA, NA, NA,
6L, 106.8, 31.9, 106.2, 32.2, NA, NA, NA, NA, NA, NA,
7L, 97, 30.7, 96.1, 29.7, 95.29, 53.5, NA, NA, NA, NA,
8L, 86.7, 28, 87.4, 28.7, NA, NA, NA, NA, NA, NA,
9L, 66.8, 20.9, 93.6, 25.7, NA, NA, NA, NA, NA, NA,
10L, 94.2, 25.6, 69.8, 21.3, 93.78, 47.4, NA, NA, NA, NA,
11L, 69.8, 21.1, 73.6, 22.7, 69.27, 37.1, NA, NA, NA, NA,
12L, 73.9, 22.7, 74.4, 24.5, 73.37, 35.9, NA, NA, NA, NA,
13L, 73.7, 23.1, 87.2, 27.8, 74.48, 38.2, NA, NA, NA, NA,
14L, 86.9, 27.7, 72.7, 19.6, 87.14, 49.1, NA, NA, NA, NA,
15L, 72, 19.5, NA, NA, 72.22, 38.64, NA, NA, NA, NA,
16L, NA, NA, 74.6, 39.3, 74.02, 40.6, 75.77, 40.64, NA, NA,
17L, NA, NA, 80.5, 45.7, 80.46, 45.5, NA, NA, NA, NA,
18L, NA, NA, 90.1, 48.6, NA, NA, NA, NA, NA, NA,
19L, NA, NA, 70.5, 37, 71.01, 36.5, NA, NA, NA, NA,
20L, NA, NA, 89.9, 48.7, 88.02, 48.8, 89.27, 48.85, NA, NA,
21L, NA, NA, 84.8, 42.5, 85.13, 43.1, NA, NA, NA, NA,
22L, NA, NA, 80.9, 45.3, NA, NA, NA, NA, NA, NA,
23L, NA, NA, 70.6, 38.1, 70.21, 37.6, NA, NA, NA, NA,
24L, NA, NA, 80.1, 42.7, 79.63, 41.9, NA, NA, NA, NA,
25L, NA, NA, 84.1, 49.8, 84.44, 49.7, NA, NA, NA, NA,
26L, NA, NA, 75.9, 38.3, 75.4, 74.4, NA, NA, NA, NA,
27L, NA, NA, 67.8, 35.5, 67.34, 34.8, NA, NA, NA, NA,
28L, NA, NA, 88.3, 44.9, 88.6, 48.1, NA, NA, NA, NA,
29L, NA, NA, 78.5, 42.7, 79.38, 42.8, 79.45, 43.22, NA, NA,
30L, NA, NA, 83, 46, 82.73, 46.1, NA, NA, NA, NA,
31L, NA, NA, 80, 46, NA, NA, 83.61, 44.86, NA, NA,
32L, NA, NA, 72, 40, NA, NA, NA, NA, NA, NA,
33L, NA, NA, 77, 44, NA, NA, NA, NA, NA, NA,
34L, NA, NA, 84, 42, 82.79, 42.5, NA, NA, NA, NA,
35L, NA, NA, 73, 37, NA, NA, NA, NA, NA, NA,
36L, NA, NA, 82, 41, 82.54, 41.4, NA, NA, NA, NA,
37L, NA, NA, 81, 45, NA, NA, NA, NA, NA, NA,
38L, NA, NA, 83, 47, 82.07, 46.7, NA, NA, NA, NA,
39L, NA, NA, 84, 45, 84.45, 44.9, NA, NA, NA, NA,
40L, NA, NA, 91, 49, 90.74, 47.7, 91.81, 48.3, NA, NA,
41L, NA, NA, 85, 44, 85.19, 45, 84.72, 45.28, NA, NA,
42L, NA, NA, 82, 46, NA, NA, NA, NA, NA, NA,
43L, NA, NA, 84, 42, NA, NA, NA, NA, NA, NA,
44L, NA, NA, 75, 41, 74.51, 41.5, NA, NA, NA, NA,
45L, NA, NA, 91, 49, 90.49, 48.8, 90.35, 46.8, NA, NA,
46L, NA, NA, 90, 50, NA, NA, NA, NA, NA, NA,
47L, NA, NA, 72, 35, 72.07, 36.7, NA, NA, NA, NA,
48L, NA, NA, 80, 43, 80.98, 43.6, 80.52, 43.75, NA, NA,
49L, NA, NA, 68, 36, 67.51, 34.8, NA, NA, NA, NA,
50L, NA, NA, 76, 41, 76.09, 41.8, NA, NA, NA, NA,
51L, NA, NA, NA, NA, 83.49, 43.4, NA, NA, NA, NA,
52L, NA, NA, NA, NA, 86.15, 47.1, NA, NA, NA, NA,
53L, NA, NA, NA, NA, 76.72, 41.3, NA, NA, NA, NA,
54L, NA, NA, NA, NA, 77.76, 45.6, NA, NA, NA, NA,
55L, NA, NA, NA, NA, 77.53, 43.5, 78.18, 43.02, NA, NA,
56L, NA, NA, NA, NA, 80.52, 42.9, NA, NA, NA, NA,
57L, NA, NA, NA, NA, 89.13, 49.6, NA, NA, NA, NA,
58L, NA, NA, NA, NA, 80.19, 45.6, NA, NA, NA, NA,
59L, NA, NA, NA, NA, 74.95, 40.1, 75.51, 40.68, NA, NA,
60L, NA, NA, NA, NA, 68.09, 35.9, 69.6, 35.48, NA, NA,
61L, NA, NA, NA, NA, 89.16, 49.8, NA, NA, NA, NA,
62L, NA, NA, NA, NA, NA, NA, 78.18, 43.02, NA, NA,
63L, NA, NA, NA, NA, NA, NA, 75.51, 40.68, NA, NA,
64L, NA, NA, NA, NA, NA, NA, 69.6, 35.48, NA, NA,
65L, NA, NA, NA, NA, NA, NA, 77.94, 41.08, NA, NA,
66L, NA, NA, NA, NA, NA, NA, 88.44, 50.5, NA, NA,
67L, NA, NA, NA, NA, NA, NA, 74.93, 40.77, NA, NA,
68L, NA, NA, NA, NA, NA, NA, 79.69, 43.17, NA, NA,
69L, NA, NA, NA, NA, NA, NA, 84.69, 84.67, NA, NA,
70L, NA, NA, NA, NA, NA, NA, 85.75, 48.82, NA, NA,
71L, NA, NA, NA, NA, NA, NA, 62.37, 33.72, NA, NA,
72L, NA, NA, NA, NA, NA, NA, 71.56, 38.59, NA, NA,
73L, NA, NA, NA, NA, NA, NA, 90.78, 47.1, NA, NA,
74L, NA, NA, NA, NA, NA, NA, 92.05, 49.47, NA, NA,
75L, NA, NA, NA, NA, NA, NA, 83.51, 49.01, NA, NA,
76L, NA, NA, NA, NA, NA, NA, 75.06, 40.91, NA, NA,
77L, NA, NA, NA, NA, NA, NA, 75.19, 38.61, NA, NA,
78L, NA, NA, NA, NA, NA, NA, 85.72, 43, NA, NA,
79L, NA, NA, NA, NA, NA, NA, 93.35, 52, NA, NA,
80L, NA, NA, NA, NA, NA, NA, 81.77, 47.66, NA, NA,
81L, NA, NA, NA, NA, NA, NA, 78.92, 42.42, NA, NA,
82L, NA, NA, NA, NA, NA, NA, 77.94, 41.08, NA, NA,
83L, NA, NA, NA, NA, NA, NA, 82.45, 43.79, NA, NA,
84L, NA, NA, NA, NA, NA, NA, 80.02, 46.88, NA, NA,
85L, NA, NA, NA, NA, NA, NA, 73.2, 72.72, NA, NA,
86L, NA, NA, NA, NA, NA, NA, 79.55, 43.99, NA, NA,
87L, NA, NA, NA, NA, NA, NA, 90.1, 48.31, NA, NA,
88L, NA, NA, NA, NA, NA, NA, 85.04, 50.29, NA, NA,
89L, NA, NA, NA, NA, NA, NA, 73.77, 41.6, NA, NA,
90L, NA, NA, NA, NA, NA, NA, 81.94, 46.83, NA, NA,
91L, NA, NA, NA, NA, NA, NA, NA, NA, 80.16, 47.69,
92L, NA, NA, NA, NA, NA, NA, NA, NA, 76.1, 44.16,
93L, NA, NA, NA, NA, NA, NA, NA, NA, 78.46, 43.42,
94L, NA, NA, NA, NA, NA, NA, NA, NA, 90.68, 50.26,
95L, NA, NA, NA, NA, NA, NA, NA, NA, 96.33, 51.32,
96L, NA, NA, NA, NA, NA, NA, NA, NA, 81.15, 47.81,
97L, NA, NA, NA, NA, NA, NA, NA, NA, 75.37, 41.31,
98L, NA, NA, NA, NA, NA, NA, NA, NA, 85.32, 46.78
)
Created on 2022-07-06 by the reprex package (v2.0.1)
thank you!