Maybe this is just the brute force you want to avoid, but it works to coerce the integer into a string, and then back to a number. Could reduce number of lines by nesting functions, of course.
y <- 1234131431 n <- 3 ychar <- as.character(y) ydigits <- nchar(ychar) result <- as.numeric ( substr(ychar, ydigits- n +1, ydigits) ) pj (Ted Harding) wrote: > Hi Folks, > > I'm trying to find a neat solution to an apparently simple > problem, but one which turns out to be a bit more intricate > and tricky than one might expect. > > Suppose I have numbers given to a large number of digits. > For example > > 1234567021 > > where (though I don't know this beforehand) only the last > 3 digits will be varying (and all 3 will vary). > > What I want is, give a vector x of such numbers, to extract > the minimal set of final digits which will include the varying > digits (i.e. in this case the last 3 digits). And there may be > a decimal point somewhere along the line (though again I won't > know where, nor whether). > -- Paul E. Johnson email: [EMAIL PROTECTED] Dept. of Political Science http://lark.cc.ku.edu/~pauljohn 1541 Lilac Lane, Rm 504 University of Kansas Office: (785) 864-9086 Lawrence, Kansas 66044-3177 FAX: (785) 864-5700 ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
