OK, I made a reprex of your code with a smaller version of da1
, and thought I'd write down the steps I took you so you can make your own in the future:
First, I created a new file with this in it:
library(tidyverse)
da1 <-
structure(list(Odeur = structure(c(1L, 3L, 4L, 5L, 5L), .Label = c("affinité -",
"affinité +", "camphre", "carnivore", "eau", "Familier", "hareng",
"merlan", "Non Familier", "poivre", "soigneur 1", "soigneur 2"
), class = "factor"), Type.de.test = structure(c(2L, 3L, 4L,
2L, 3L), .Label = c("affinité - vs affinité +", "affinité - vs eau",
"camphre vs eau", "carnivore vs eau", "eau vs familier", "eau vs hareng",
"eau vs merlan", "eau vs non familier", "eau vs poivre", "eau vs soigneur 1",
"eau vs soigneur 2", "familier vs non familier", "hareng vs merlan",
"soigneur 1 vs soigneur 2"), class = "factor"), Nombre.de.contacts = c(2.8,
1.6, 1.6, 2, 1.6), sd = c(2.16794833886788, 0.894427190999916,
0.894427190999916, 1.73205080756888, 0.894427190999916)), row.names = c(NA,
-5L), class = "data.frame")
### end of dput() output
# inspect da1
da1
(I included the library()
command because in order to be reproducible -- that is anyone can copy and paste it into their own machine and have it work -- the code should be self-contained, and the dplyr
functions we'll need are contained within the tidyverse
package.)
Second, I copied -- but did not yet paste -- all of this code, and immediately ran the command reprex()
from the reprex
package you'd need to install.
Last, before doing any more copying or pasting, I pasted here to get my reprex version:
library(tidyverse)
da1 <-
structure(list(Odeur = structure(c(1L, 3L, 4L, 5L, 5L), .Label = c("affinité -",
"affinité +", "camphre", "carnivore", "eau", "Familier", "hareng",
"merlan", "Non Familier", "poivre", "soigneur 1", "soigneur 2"
), class = "factor"), Type.de.test = structure(c(2L, 3L, 4L,
2L, 3L), .Label = c("affinité - vs affinité +", "affinité - vs eau",
"camphre vs eau", "carnivore vs eau", "eau vs familier", "eau vs hareng",
"eau vs merlan", "eau vs non familier", "eau vs poivre", "eau vs soigneur 1",
"eau vs soigneur 2", "familier vs non familier", "hareng vs merlan",
"soigneur 1 vs soigneur 2"), class = "factor"), Nombre.de.contacts = c(2.8,
1.6, 1.6, 2, 1.6), sd = c(2.16794833886788, 0.894427190999916,
0.894427190999916, 1.73205080756888, 0.894427190999916)), row.names = c(NA,
-5L), class = "data.frame")
### end of dput() output
# inspect da1
da1
#> Odeur Type.de.test Nombre.de.contacts sd
#> 1 affinité - affinité - vs eau 2.8 2.1679483
#> 2 camphre camphre vs eau 1.6 0.8944272
#> 3 carnivore carnivore vs eau 1.6 0.8944272
#> 4 eau affinité - vs eau 2.0 1.7320508
#> 5 eau camphre vs eau 1.6 0.8944272
Created on 2020-03-04 by the reprex package (v0.3.0)
Now, for you question, here's a suggested solution:
library(tidyverse)
da1 <-
structure(list(Odeur = structure(c(1L, 3L, 4L, 5L, 5L), .Label = c("affinité -",
"affinité +", "camphre", "carnivore", "eau", "Familier", "hareng",
"merlan", "Non Familier", "poivre", "soigneur 1", "soigneur 2"
), class = "factor"), Type.de.test = structure(c(2L, 3L, 4L,
2L, 3L), .Label = c("affinité - vs affinité +", "affinité - vs eau",
"camphre vs eau", "carnivore vs eau", "eau vs familier", "eau vs hareng",
"eau vs merlan", "eau vs non familier", "eau vs poivre", "eau vs soigneur 1",
"eau vs soigneur 2", "familier vs non familier", "hareng vs merlan",
"soigneur 1 vs soigneur 2"), class = "factor"), Nombre.de.contacts = c(2.8,
1.6, 1.6, 2, 1.6), sd = c(2.16794833886788, 0.894427190999916,
0.894427190999916, 1.73205080756888, 0.894427190999916)), row.names = c(NA,
-5L), class = "data.frame")
### end of dput() output
# store sum of 'Nombre.de.contacts' in a new column I called 'total'
da1 %>%
summarise(total = sum(Nombre.de.contacts))
#> total
#> 1 9.6
Created on 2020-03-04 by the reprex package (v0.3.0)