I would like to calculate to the first decimal using integer numbers but whatever I do, it is rounded and does not give me the precision I want. I have spent a lot of time looking up and it seems something a lot of beginners like me would have a problem with but I cannot find a solution to what could be done easily.
Here are my codes:
type = c('A', 'B', 'C', 'D', 'C', 'B')
count = c(1, 4, 8, 4, 2, 4)
df1 = data.frame(type, count)
type2 = c('A', 'B', 'C', 'D', 'B', 'C', 'D', 'A')
count2 = c(3, 7, 1, 4, 8, 4, 5, 2)
df2 = data.frame(type2, count2)
sum1 <- tapply(df1$count, type, sum)
sum2 <- tapply(df2$count2, type2, sum)
round(sum1/sum2*100.0, 1) # Want to calculate it to the 1st decimal
I get this:
A B C D
20 53 200 44
and I want this:
A B C D
20.0 53.3 200.0 44.4
I appreciate your help in advance.