Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step 4.2 #53

Open
mzk5991 opened this issue Feb 29, 2024 · 1 comment
Open

Step 4.2 #53

mzk5991 opened this issue Feb 29, 2024 · 1 comment
Labels
Fixed A solution is attached. Great issue format Nice work! You included everything I need to solve this

Comments

@mzk5991
Copy link

mzk5991 commented Feb 29, 2024

Is there any reason why this is only showing up to 2 sig-figs? I assume because last digit is 0? How do I make it appear 0 as well?

meanppl <- round(mean(dataC$Town Population (1000 pp), na.rm = TRUE),3)
meanppl

output
[1] 35.19

@hgreatrex
Copy link
Contributor

hgreatrex commented Mar 1, 2024

You are right - it's because of the final 0.

You don't need to fix this, but if you wanted to - there are (at least) three options. All of these turn the number into a character word (e.g. the quote marks). So you would no longer be able to use it for calculations, but its fine for printing out.

sprintf('%.2f', meanppl)
format(round(meanppl, digits=2), nsmall = 2)
formatC(meanppl,2,format="f")

Note to find this answer, I googled R round show final zero
which led me here - https://stackoverflow.com/questions/42105336/how-to-round-a-number-and-make-it-show-zeros

Note- in terms of code format - I would consider renaming your columns to something easy to type like population. It just makes it easier to write code in circumstances when you can't autoselect the column using $.

@hgreatrex hgreatrex added Fixed A solution is attached. Great issue format Nice work! You included everything I need to solve this labels Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed A solution is attached. Great issue format Nice work! You included everything I need to solve this
Projects
None yet
Development

No branches or pull requests

2 participants