标签:ret width r语言 [1] justify 语法 res minimum ring
数字和字符串可以使用 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 "
标签:ret width r语言 [1] justify 语法 res minimum ring
原文地址:http://www.cnblogs.com/csguo/p/7294080.html