在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
数字和字符串可以使用 format()函数的格式化为特定样式。 语法format()函数的基本语法是: format(x, digits, nsmall,scientific,width,justify = c("left", "right", "centre", "none")) 以下是所使用的参数的说明:
示例# Total number of digits displayed. Last digit rounded off. result <- format(23.123456789, digits = 9) print(result) # Display numbers in scientific notation. result <- format(c(6, 13.14521), scientific = TRUE) print(result) # The minimum number of digits to the right of the decimal point. result <- format(23.47, nsmall = 5) print(result) # Format treats everything as a string. result <- format(6) print(result) # Numbers are padded with blank in the beginning for width. result <- format(13.7, width = 6) print(result) # Left justify strings. result <- format("Hello",width = 8, justify = "l") print(result) # Justfy string with center. result <- format("Hello",width = 8, justify = "c") print(result) 当我们上面的代码执行时,它产生以下结果: [1] "23.1234568" [1] "6.000000e+00" "1.314521e+01" [1] "23.47000" [1] "6" [1] " 13.7" [1] "Hello " [1] " Hello " |
请发表评论