Working with two.. factors to get a arthimetic mean

Hello,

I'm basiclly completly new to R, but I'm required to use it for a paper I'm writing at. So far I was able to get the basics like, summary and getting the overall arihmetic means and so on. My Problem now is, That I basiclly have two factor of Data that I aquired
One is the kind of Data (One is the Estaury of the bird species I'm writing about, the other is Control Plots. Than this two are divided into a South and Noth Area. So now I need to compare North, South and Control Plots and estuarys. So for example I want the mean of all Northern estuarys and than off all Southern control plots. I don't really get around how to do this, I was thinking about with a data frame maybe?

Thanks for your Help in forward :slight_smile:

Yes, you should load the data into a data frame. You can then use functions from the dplyr package to group the data and compute means. Here is an example using data I invented where E and C represent Estuary and Control and N and S represent North and South.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#Invent data
DF <- data.frame(Kind=c("E","E","E","E","C","C","C","C"),
                 Loc=c("N","S","N","S","N","S","N","S"),
                 Value=runif(n = 8,min = 10,max = 25))
print(DF)
#>   Kind Loc    Value
#> 1    E   N 11.82269
#> 2    E   S 10.01236
#> 3    E   N 13.66709
#> 4    E   S 12.81534
#> 5    C   N 18.59053
#> 6    C   S 23.57225
#> 7    C   N 23.96505
#> 8    C   S 12.88673

DF_means <- DF |> group_by(Kind,Loc) |> summarize(Avg=mean(Value))
#> `summarise()` has grouped output by 'Kind'. You can override using the `.groups` argument.
DF_means
#> # A tibble: 4 x 3
#> # Groups:   Kind [2]
#>   Kind  Loc     Avg
#>   <chr> <chr> <dbl>
#> 1 C     N      21.3
#> 2 C     S      18.2
#> 3 E     N      12.7
#> 4 E     S      11.4

Created on 2021-11-27 by the reprex package (v2.0.1)

Ok Thanks, thats helping already. So I need to put in every Point from hand? (There have been 88 Data points) Is there a faster method, or do I misunderstand something completly?

You should not have to enter the data manually. How are the data stored?

Hmm best is I give you a Screenshot about how it looks in Excel:

Excel

You can read the data from an excel file into a data frame. One way to do that is to use a package like readxl and its function read_excel(). You can install the package with

install.packages("readxl")

The code to read in the file might look like

library(readxl)

DF <- read.excel("FileName.xlsx")

You could then something like

DF_means <- DF |> group_by(Kind, Area) |> summarize(Avg=mean(Value))

Your image does not show the column storing the values, so I used a generic name for that.

O, I tried now the last few days to import the excel file into R but it gives me now this Error:

Error: '\M' is an unrecognized escape in character string starting ""C:\Users\nagra\OneDrive\Dokumente\M"

Use forward slashes or double backslashes

C:/Users/nagra/OneDrive/Dokumente/M
or
C:\\Users\\nagra\\OneDrive\\Dokumente\\M

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.