hi R-users! does anyone know how I can access/print only the first two digits of a number? if i have the number 23732, i would like to get 23. if i have 355 i would like to get 35. if i have 4 i would like to get 40. thanks for your help! christian
On Wed, Sep 29, 2010 at 7:18 PM, Christian Schoder <schoc152 at newschool.edu> wrote:> hi R-users! > > does anyone know how I can access/print only the first two digits of a > number? if i have the number 23732, i would like to get 23. if i have > 355 i would like to get 35. if i have 4 i would like to get 40.It's a strange request, but this should do it: substring(as.character(number*100), 1, 2) It will not work on 0 and may not give you what you want on negative numbers and on numbers between 0 and 1, but you get the idea. Peter
Try this: trunc(x / 10 ^ nchar(x) * 100) On Wed, Sep 29, 2010 at 11:18 PM, Christian Schoder <schoc152@newschool.edu>wrote:> hi R-users! > > does anyone know how I can access/print only the first two digits of a > number? if i have the number 23732, i would like to get 23. if i have > 355 i would like to get 35. if i have 4 i would like to get 40. > > thanks for your help! > > christian > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]