zoukankan      html  css  js  c++  java
  • R sprintf函数

    ------------恢复内容开始------------
    看到sprintf函数有点不明所以,原文如下

    为了用指定的格式数值型转换成字符型, 可以使用sprintf()函数, 其用法与C语言的sprintf()函数相似, 只不过是向量化的。例如
    sprintf('file%03d.txt', c(1, 99, 100))
    ## [1] "file001.txt" "file099.txt" "file100.txt"

    sprintf()

    Use C-style String Formatting Commands

    Description

    A wrapper for the C function sprintf, that returns a character vector containing a formatted combination of text and variable values.

    Usage

    sprintf(fmt, ...)
    gettextf(fmt, ..., domain = NULL)
    Arguments
    fmt 格式化字符串
    a character vector of format strings, each of up to 8192 bytes.

    ...
    values to be passed into fmt. Only logical, integer, real and character vectors are supported, but some coercion will be done: see the ‘Details’ section. Up to 100.

    domain
    see gettext.

    Details
    sprintf is a wrapper for the system sprintf C-library function. Attempts are made to check that the mode of the values passed match the format supplied, and R's special values (NA, Inf, -Inf and NaN) are handled correctly.

    gettextf is a convenience function which provides C-style string formatting with possible translation of the format string.

    The arguments (including fmt) are recycled if possible a whole number of times to the length of the longest, and then the formatting is done in parallel. Zero-length arguments are allowed and will give a zero-length result. All arguments are evaluated even if unused, and hence some types (e.g., "symbol" or "language", see typeof) are not allowed.

    The following is abstracted from Kernighan and Ritchie (see References): however the actual implementation will follow the C99 standard and fine details (especially the behaviour under user error) may depend on the platform.
    ------------恢复内容结束------------

  • 相关阅读:
    .htaccess
    windows快速搭建wamp环境,多站点域名访问
    require与include的区别
    PHP常用操作的字符串函数
    高效做事的习惯
    成功?!
    面向对象程序设计
    失落 绝望
    jquery学习收获
    XML操作类
  • 原文地址:https://www.cnblogs.com/impw/p/13028521.html
Copyright © 2011-2022 走看看