Я попробовал это:
library(tidyverse)
library(readxl)
df <- read_excel("YOUR_XLSX_FILE")
df %>%
gather(date, temp, -x, -y) %>%
separate(date, c("year", "month", "day")) %>%
separate(year, c("trash", "year"), sep = "X") %>%
select(-trash) %>%
group_by(year, x, y) %>%
summarise(avg_temp=mean(temp)) %>%
spread(year, avg_temp)
вывод:
# A tibble: 19 x 17
# Groups: x [11]
x y `1980` `1981` `1982` `1983` `1984` `1985` `1986` `1987` `1988` `1989` `1990` `1991`
* <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 8.88 54.4 7.79 8.02 8.76 9.20 8.32 7.51 7.88 7.43 9.20 9.63 9.76 8.55
2 8.88 54.9 7.54 7.61 8.41 8.84 8.15 7.15 7.53 7.15 8.97 9.51 9.55 8.42
3 9.12 54.4 7.65 7.86 8.62 9.05 8.17 7.34 7.70 7.28 9.01 9.46 9.60 8.37
4 9.12 54.6 7.44 7.59 8.38 8.81 8.02 7.11 7.50 7.13 8.88 9.36 9.47 8.31
5 9.12 54.9 7.33 7.36 8.25 8.67 8.02 7.05 7.49 7.10 8.91 9.48 9.55 8.41
6 9.38 54.4 7.69 7.91 8.61 9.02 8.15 7.31 7.69 7.24 8.98 9.49 9.64 8.35
7 9.38 54.6 7.45 7.62 8.46 8.85 8.05 7.16 7.59 7.18 8.92 9.48 9.61 8.41
8 9.38 54.9 7.24 7.29 8.21 8.62 7.95 7.04 7.56 7.15 8.94 9.57 9.66 8.53
9 9.62 54.4 7.65 7.90 8.60 9.01 8.14 7.24 7.64 7.16 8.93 9.52 9.65 8.33
10 9.62 54.6 7.39 7.60 8.45 8.82 8.01 7.10 7.56 7.12 8.86 9.46 9.55 8.34
11 9.62 54.9 7.28 7.38 8.28 8.69 7.98 7.07 7.61 7.18 8.96 9.60 9.68 8.54
12 9.88 54.4 7.70 8.00 8.69 9.14 8.23 7.36 7.76 7.23 9.03 9.63 9.73 8.41
13 9.88 54.6 7.40 7.65 8.46 8.87 8.05 7.11 7.58 7.12 8.87 9.47 9.50 8.30
14 10.1 54.4 7.76 8.12 8.78 9.21 8.30 7.49 7.90 7.34 9.08 9.69 9.79 8.52
15 10.4 54.4 7.66 8.09 8.70 9.17 8.23 7.41 7.87 7.29 9.03 9.70 9.82 8.60
16 11.1 54.9 7.61 8.14 8.74 9.14 8.33 7.32 7.92 7.22 9.17 9.93 10.1 8.86
17 11.4 54.9 7.59 8.17 8.74 9.14 8.32 7.29 7.92 7.20 9.17 9.95 10.1 8.87
18 11.9 54.9 7.54 8.15 8.71 9.10 8.28 7.19 7.85 7.15 9.10 9.92 10.1 8.84
19 12.1 54.9 7.52 8.12 8.69 9.08 8.27 7.12 7.80 7.11 9.05 9.91 10.0 8.82
# ... with 3 more variables: `1992` <dbl>, `1993` <dbl>, `1994` <dbl>
, чтобы показать вам, что геокординаты не изменились в tibble
(он просто округлен), добавьте as.data.frame()
в конце канала и посмотрите на свои данные: пример:
df %>%
gather(date, temp, -x, -y) %>%
separate(date, c("year", "month", "day")) %>%
separate(year, c("trash", "year"), sep = "X") %>%
select(-trash) %>%
group_by(year, x, y) %>%
summarise(avg_temp=mean(temp)) %>%
spread(year, avg_temp) %>%
as.data.frame() %>% # add this
head()
вывод:
# x y 1980 1981 1982 1983 1984 1985 1986 1987 1988
# 1 8.875 54.375 7.792978 8.021342 8.762274 9.203424 8.317131 7.505370 7.879068 7.427260 9.197431
# 2 8.875 54.875 7.536229 7.607507 8.414877 8.841260 8.154945 7.151890 7.532164 7.147945 8.969781
# 3 9.125 54.375 7.651393 7.862466 8.620904 9.052630 8.169262 7.337589 7.701205 7.282657 9.014590
# 4 9.125 54.625 7.435983 7.590548 8.381753 8.808904 8.019399 7.109096 7.499589 7.127370 8.875656
# 5 9.125 54.875 7.332978 7.363370 8.247205 8.669370 8.024645 7.045425 7.487424 7.098849 8.911776
# 6 9.375 54.375 7.693907 7.914630 8.612438 9.022055 8.150164 7.305068 7.688164 7.242274 8.984207
# 1989 1990 1991 1992 1993 1994
# 1 9.625781 9.760931 8.550356 9.678907 8.208109 9.390904
# 2 9.513863 9.552767 8.420109 9.425328 8.010082 9.134466
# 3 9.462959 9.602876 8.374575 9.465164 8.052794 9.207041
# 4 9.358986 9.473178 8.305863 9.353743 7.935507 9.050109
# 5 9.478192 9.545781 8.412329 9.403005 7.998877 9.074740
# 6 9.493205 9.635561 8.352740 9.385819 8.017260 9.184959