Very helpful -- thanks, @hardwax: This helps folks understand your situation better. For example, it tells us you have non-numeric columns, so you can use a tweak of @nirgrahamuk's suggestion:
library(tidyverse)
your_table <-
structure(list(country = c("Afghanistan", "Afghanistan", "Afghanistan",
"Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan",
"Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan",
"Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan",
"Afghanistan", "Afghanistan"), iso3c = c("AFG", "AFG", "AFG",
"AFG", "AFG", "AFG", "AFG", "AFG", "AFG", "AFG", "AFG", "AFG",
"AFG", "AFG", "AFG", "AFG", "AFG", "AFG", "AFG", "AFG"), date = structure(c(18283,
18284, 18285, 18286, 18287, 18288, 18289, 18290, 18291, 18292,
18293, 18294, 18295, 18296, 18297, 18298, 18299, 18300, 18301,
18302), class = "Date"), confirmed = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), deaths = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), deathgrowth = c(NA,
NA, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN)), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"), row.names = c(NA, -20L), groups = structure(list(
country = "Afghanistan", .rows = list(1:20)), row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE))
### end of 'structure()' command
your_table %>%
# change NA's and NaN's to 0 for numeric columns
mutate_if(is.numeric, ~ if_else(is.na(.), 0, .)) %>%
head()
#> `mutate_if()` ignored the following grouping variables:
#> Column `country`
#> # A tibble: 6 x 6
#> # Groups: country [1]
#> country iso3c date confirmed deaths deathgrowth
#> <chr> <chr> <date> <dbl> <dbl> <dbl>
#> 1 Afghanistan AFG 2020-01-22 0 0 0
#> 2 Afghanistan AFG 2020-01-23 0 0 0
#> 3 Afghanistan AFG 2020-01-24 0 0 0
#> 4 Afghanistan AFG 2020-01-25 0 0 0
#> 5 Afghanistan AFG 2020-01-26 0 0 0
#> 6 Afghanistan AFG 2020-01-27 0 0 0
Created on 2020-03-25 by the reprex package (v0.3.0)
Also, notice my code includes the package I'm using as well as creates the table and uses it -- this makes it easy for folks to copy and paste when they're helping you, and is one step closer to the reprex @andresrcs asked for.