[R] rounding up to nearest integer
Nikhil Kaza
nikhil.list at gmail.com
Tue May 25 03:39:56 CEST 2010
?round
On May 24, 2010, at 9:26 PM, Mohan L wrote:
> Dear All,
>
> I have a data frame "data" and the below is the str of "data" :
>
> $ Feb : int 1 1195 0 11 28 152 24 2 1 1470 ...
> $ Mar : int 0 1212 0 17 27 184 15 1 1 1311 ...
> $ Apr : int 2 1244 1 15 23 135 11 0 1 991 ...
> $ May : int 2 1158 2 10 23 111 16 1 1 1237 ...
> $ Jun : int 0 845 1 9 16 86 16 2 1 1129 ...
> $ Jul : int 0 832 0 7 16 68 9 1 0 994 ...
> $ Aug : int 0 1107 1 4 25 144 7 0 3 1260 ...
> $ Sep : int 2 1278 1 8 53 212 14 0 3 1375 ...
> $ Oct : int 3 1329 0 8 39 201 13 0 0 1340 ...
> $ Nov : int 1 1179 0 5 7 135 2 0 0 1153 ...
> $ Dec : int 0 1271 0 7 34 168 5 1 2 1792 ...
> $ Jan.10: int 0 1405 1 10 55 245 26 2 4 2806 ...
> $ Feb.10: int 0 1330 1 9 29 360 27 3 6 3492 ...
> $ Mar.10: int 0 1727 0 8 7 341 8 2 4 4578 ...
> $ Apr.10: int 0 1530 1 8 12 144 7 2 2 5453 ...
>
> I am doing some this like this :
>
>> x <- (data[,-(1:2)] - data[,2]) * prop.table(data[,2]) + data[,2]
>> x
> Feb Mar Apr May Jun
> Jul
> 1 1.000000 0.9999597 1.0000403 1.0000403 0.9999597
> 0.9999597
> 2 1292.610851 1293.5003225 1295.1746211 1290.6749436 1274.2982103
> 1273.6180264
>
> Now the str of "x" is :
>
>> str(x)
> 'data.frame': 32 obs. of 15 variables:
> $ Feb : num 1 1293 0 5 18 ...
> $ Mar : num 1 1294 0 5 18 ...
> $ Apr : num 1 1295 0 5 18 ...
> $ May : num 1 1291 0 5 18 ...
> $ Jun : num 1 1274 0 5 18 ...
> $ Jul : num 1 1274 0 5 18 ...
> $ Aug : num 1 1288 0 5 18 ...
> $ Sep : num 1 1297 0 5 18 ...
> $ Oct : num 1 1300 0 5 18 ...
> $ Nov : num 1 1292 0 5 18 ...
> $ Dec : num 1 1297 0 5 18 ...
> $ Jan.10: num 1 1303.6 0 5 18 ...
> $ Feb.10: num 1 1300 0 5 18 ...
> $ Mar.10: num 1 1320 0 5 18 ...
> $ Apr.10: num 1 1310 0 5 18 ...
>
> I need to round up the data frame some thing like this :
>
> Feb Mar Apr May
> Jun Jul
> 1 1 1 1 1 1
> 1
> 2 1293 1294 1295 1291 1274
> 1274
>
> there may be a way to round up the nearest integer. any help will be
> greatly
> appropriated.
>
> Thanks & Rg
> Mohan L
>
> [[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