R Func Ceiling
# R ceiling() and floor() functions β Round Up\\\\n\\\\nR provides multiple rounding functions: ceiling() rounds up, floor() rounds down, trunc() truncates toward zero.\\\\n\\\\nThese functions are commonly used in numerical discretization, binning processing, and resource allocation calculations.\\\\n\\\\nThe syntax of each function is as follows:\\\\n\\\\nceiling(x) # Round UpοΌsmallest integer not less than x)\\\\nfloor(x) # Round down (largest integer not greater than x)\\\\ntrunc(x) # Truncate towards zero\\\\n\\\\n**Parameter Description:**\\\\n\\\\n* **x** - Input numeric value or numeric vector.\\\\n\\\\n## Example\\\\n\\\\n```r\\\\nx <-c(3.14, -3.14, 5.99, -5.99, 2.0)\\\\n\\\\n# ceiling: Round Up\\\\n\\\\nprint("ceilingοΌup):")\\\\n\\\\nprint(ceiling(x))\\\\n\\\\n# floor: Round Down\\\\n\\\\nprint("floorοΌdown):")\\\\n\\\\nprint(floor(x))\\\\n\\\\n# trunc: Truncate towards zero\\\\n\\\\nprint("truncοΌtruncate towards zero):")\\\\n\\\\nprint(trunc(x))\\\\n\\\\nExecuting the above code outputs:\\\\n\\\\n "ceilingοΌup):"\\\\n 4 -3 6 -5 2\\\\n "floorοΌdown):"\\\\n 3 -4 5 -6 2\\\\n "truncοΌtruncate towards zero):"\\\\n 3 -3 5 -5 2\\\\n\\\\nceiling() is very useful in pagination calculations:\\\\n\\\\n## Example\\\\n\\\\n```r\\\\n# Pagination calculation: display 20 records per page\\\\n\\\\n total_items <-103\\\\n\\\\n items_per_page <-20\\\\n\\\\n# Calculate the total number of pages needed (Round Up)\\\\n\\\\n total_pages <-ceiling(total_items / items_per_page)\\\\n\\\\nprint(paste(total_items, "recordsdataοΌperPage", items_per_page,\\\\n\\\\n"records, requiring a total of", total_pages, "Page"))\\\\n\\\\nExecuting the above code outputs:\\\\n\\\\n "103 recordsData, 20 records per page, requiring a total of 6 Page"
YouTip