This is my tibble.
Simply trying to find the % of count (cases) in population. Shouldn't the '/' work on dbls?
Help. Thanks.
This is my tibble.
Simply trying to find the % of count (cases) in population. Shouldn't the '/' work on dbls?
Help. Thanks.
Please consider creating a minimal reproducible example in your question to make it easier for others to modify your code and spot errors. Your question would also benefit from being more specific.
Putting together the pieces from your screenshots, I assume you would like to create a new column by dividing an existing column by another existing column. The function to do this is mutate()
, not add_column()
:
library(dplyr)
df <- tibble(
country = "Australia",
count = 8,
population = 18.4
)
df |> mutate(pct_pop = (count / 1e6) / population)
#> # A tibble: 1 × 4
#> country count population pct_pop
#> <chr> <dbl> <dbl> <dbl>
#> 1 Australia 8 18.4 0.000000435
Created on 2023-02-19 with reprex v2.0.2
It looks a bit odd that you are dividing the cases by a million, rather than population. Make sure you didn't get that wrong.