课程: R for Data Science: Lunch Break Lessons

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

floor, round, ceiling, and trunc

floor, round, ceiling, and trunc

- [Instructor] Rounding numbers is a pretty basic need, and R provides several functions that'll allow you to do rounding in different ways. It's worth some time to take a look at how these functions work and their different behaviors. To start, I've created a vector called someFractions and into it I've placed various floating point numbers. The first thing I'm going to use is round and let's round off some fractions and see what happens to the numbers. It's exactly what you'd expect. Any number less than halfway between the number above and below is rounded down and anything above halfway is rounded up. So 3.5 is turned into four. Now there's also a function called floor and you can see what floor has done is rounded everything down. So 3.5 becomes three, four remains four. Along with floor you have ceiling. Ceiling does the opposite of floor which any number following the actual number itself, such as 3.1 or 3.15, is rounded up to the next number coming in. So 3.15 is turned into…

内容