0

I have a data-frame with some columns em formato numerico. I have also columns with year, season clim and sampling station name.

I would like to calculate the mean of each numeric column grouped for year, station name and season clim.

I achieved to calculate mean of temperatura, but I could not to calculate for others column.

my data-frame exemple (OBS: some are no-data):

sample_station  Temperature Rain_24H    Wind_speed  Bar_atm season  year_date
A       S   3.001   1.611111111 rainy   2000
A   20  N   6.332   1.311111111 dry 2000
A   24  N   9.321   1.236111111 rainy   2001
A   19  N   10.9091 1.202020202 dry 2001
A   17          1.182539683 dry 2002
A   19  S   10.5882 1.169934641 rainy   2002
A   23  N   10.5    1.161111111 rainy   2002
A   26  N   10.4348 1.154589372 rainy   2002
A   19  N   10.3846 1.14957265  rainy   2002
A   19  S   10.3448 1.14559387  dry 2002
A       S   10.3125 1.142361111 dry 2002
B   15  N       1.13968254  rainy   2000
B   23  N   10.2632 1.137426901 dry 2000
B   18      10.2439 1.135501355 rainy   2001
B   22  S   10.2273 1.133838384 dry 2001
B   22  S   10.2128 1.132387707 dry 2002
B   23  N   10.2    1.131111111 rainy   2002
B   18  N   10.1887 1.129979036 rainy   2002
B           10.1786 1.128968254 rainy   2002
B   26  S       1.128060264 rainy   2002
B   21  N   10.1613 1.127240143 dry 2001
C   22  N   10.1538 1.126495726 rainy   2000
C   23      10.1471 1.125816993 dry 2000
C   27  S   10.1408 1.125195618 dry 2001
C   19  S   10.1351 1.124624625 dry 2001
C   19  N   10.1299 1.124098124 dry 2002
C   21  N   10.125  1.123611111 rainy   2002
C   23  N       1.123159304 rainy   2002
C   24  S   10.1163 1.122739018 rainy   2002
C   25  S   10.1124 1.122347066 rainy   2002
C   26  N   10.1087 1.121980676 dry 2002
A   29  N       1.121637427 rainy   2000
B   30      10.102  1.121315193 rainy   2000
C       S   10.099  1.121012101 rainy   2000
A   25  S   10.0962 1.120726496 dry 2001
B   24  N   10.0935 1.120456906 dry 2001
C   23  N   10.0909 1.12020202  dry 2001

file xlsx:https://drive.google.com/file/d/1K4ihD_IQMfH8MyBwJmW6Rg7OQ1Iwh4oC/view?usp=sharing

my try and code:

Here ok is perfect to calculate mean of temperature for sampling station, year and season

dataframe<-read_excel("D:/.../dataframe.xlsx")

dataframe%>%
  group_by(sample_station,year_date,season)%>%
  summarise(mean_temperature=mean(Temperature))

but, when i add summarise(mean_Wind_speed=mean(Wind_speed)) for to calculate the mean of Wind Speed i have problems:

dataframe<-read_excel("D:/.../dataframe.xlsx")

    dataframe%>%
      group_by(sample_station,year_date,season)%>%
      summarise(mean_temperature=mean(Temperature))%>%
      summarise(mean_Wind_speed=mean(Wind_speed))

erro:

Erro: Problem with `summarise()` input `mean_Wind_speed`. x objeto 'Wind_speed' não encontrado i Input `mean_Wind_speed` is `mean(Wind_speed)`. i The error occurred in group 1: sample_station = "A", year_date = 2000
wesleysc352
  • 579
  • 1
  • 8
  • 21
  • 2
    Did you notice that after your first `summarize(.)` call, you no longer have a `Wind_speed` column? When you get an error with one command in a pipe, look at the data *before* that function and see if it looks like you expect. In this case, since you do not somehow include `Wind_speed` in your summarization, you lose it. – r2evans May 10 '21 at 03:53
  • 2
    Try `dataframe %>% group_by(sample_station, year_date, season) %> summarize(across(where(is.numeric), mean))` – MrFlick May 10 '21 at 03:56
  • 1
    Is this really a duplicate of ? I think the difference is `where(is.numeric)`. In the OP's dataframe there are not only numeric columns. The other solution has only numeric values in the dataframe? – TarJae May 10 '21 at 04:11
  • @r2evans, yes you is correct. – wesleysc352 May 10 '21 at 04:34
  • @MrFlick, thanks you solution it helped me. – wesleysc352 May 10 '21 at 04:34
  • @TarJae, yes I saw it now, but I hadn't found it before. – wesleysc352 May 10 '21 at 04:34

0 Answers0