-1
Com %<>% mutate(precipitation=as.integer(prcp))

Com %<>% mutate(averagetemperature=as.integer(avtemp))

Com %<>% mutate(populationsize=as.integer(size))

Com %<>% mutate(numberoflymediseasecases=as.integer(cases))

This was my attempt to create four new columns, but I am recieving an error message for this code chunk

Phil
  • 7,287
  • 3
  • 36
  • 66
  • 4
    Hello Kayla. We are not able to help without further information. What does your data look like? What error are you getting? A minimally reproducible example would help to determine what is wrong. – Phil Jun 04 '20 at 21:06
  • 2
    Like @Phil said, here are some references for framing questions *well* to help us help you. Thanks! https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jun 04 '20 at 21:37

1 Answers1

0

First, you use the pipe %>% incorrectly. That is the main problem. Second, it is better to use mutate once instead of four times. Also not sure why do you use as integer, but this is a solution for you.

Com %>% mutate(precipitation=as.integer(prcp),
               averagetemperature=as.integer(avtemp),
               populationsize=as.integer(size),
               numberoflymediseasecases=as.integer(cases)) 

Output

 prcp avtemp  size cases precipitation averagetemperature populationsize numberoflymediseasecases
 <dbl>  <dbl> <dbl> <dbl>         <int>              <int>          <int>                    <int>
1    40     30     2   100            40                 30              2                      100
2    50     32     3   200            50                 32              3                      200
3    60     21     4   300            60                 21              4                      300
4    70      2     5   400            70                  2              5                      400
5    80     30     6   500            80                 30              6                      500

If you do not want duplicate columns, select only new ones:

Com %>% mutate(precipitation=as.integer(prcp),
               averagetemperature=as.integer(avtemp),
               populationsize=as.integer(size),
               numberoflymediseasecases=as.integer(cases)) %>%
        select(precipitation, averagetemperature, 
               populationsize, numberoflymediseasecases)

Output

  precipitation averagetemperature populationsize numberoflymediseasecases
      <int>              <int>          <int>                    <int>
1            40                 30              2                      100
2            50                 32              3                      200
3            60                 21              4                      300
4            70                  2              5                      400
5            80                 30              6                      500

If you can mutate columns and assign a specific column type, using Changing column types with dplyr

If you specify exactly what are you trying to do, I will try to help additionally.

Anakin Skywalker
  • 2,400
  • 5
  • 35
  • 63