[R] Format Integers

arun smartpink111 at yahoo.com
Fri Feb 15 07:55:28 CET 2013


Hi,
Try 

vec1<- c(1000000000, 1000153846, 1000307692, 1000461538, 1000615385) 

round(vec1/1e6,2)
#[1] 1000.00 1000.15 1000.31 1000.46 1000.62
#or
as.numeric(sprintf("%.2f",vec1/1e6))
#[1] 1000.00 1000.15 1000.31 1000.46 1000.62
A.K.



----- Original Message -----
From: Alaios <alaios at yahoo.com>
To: R help <R-help at r-project.org>
Cc: 
Sent: Friday, February 15, 2013 1:41 AM
Subject: [R] Format Integers

Dear all,
I would like to format the following numbers

xLabel
 [1] 1000000000 1000153846 1000307692 1000461538 1000615385 1000769231
 [7] 1000923077 1001076923 1001230769 1001384615 1001538462 1001692308
[13] 1001846154 1002000000 1002153846 1002307692 1002461538 1002615385
[19] 1002769231 1002923077 1003076923 1003230769 1003384615 1003538462
[25] 1003692308 1003846154 1004000000 1004153846 1004307692 1004461538
[31] 1004615385 1004769231 1004923077 1005076923 1005230769 1005384615
[37] 1005538462 1005692308 1005846154 1006000000 1006153846 1006307692
[43] 1006461538 1006615385 1006769231 1006923077 1007076923 1007230769
[49] 1007384615 1007538462 1007692308 1007846154 1008000000 1008153846
[55] 1008307692 1008461538 1008615385 1008769231 1008923077 1009076923
[61] 1009230769 1009384615 1009538462 1009692308 1009846154 1010000000


that are in watts to megawatts so they appear (as an example)


from: 1009846154 to 1009.846154 and even better to truncate it a bit to look better as

                                   1009.84 

Could you please help with the formatting ?

Regards
Alex
    [[alternative HTML version deleted]]


______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list