I have a vector that contains both integers and numbers with decimal places. I want to only display decimal places as necessary. For example, I have the following vector:
vec <- c(0.01, 0.1, 1, 10)
R currently displays the values as such:
> vec
[1] 0.01 0.10 1.00 10.00
The output I'm looking for would be this:
0.01 0.1 1 10
Thus far, I've only been able to round all values of the vector to the same decimal place. Thanks!
as.character(vec)
returns"0.01" "0.1" "1" "10"
. This turns yournumeric
vector into acharacter
vector (which I assume is fine since you're asking after output formatting). Is this what you're after? – Maurits EversformatC(vec)
orprettyNum(vec)
. – GKi