ID EN
String Functions

format

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Format objek R untuk pencetakan cantik.

Syntax

R
format(x, &#8230;)<p></p><p># S3 method for default
format(x, trim = FALSE, digits = NULL, nsmall = 0L,
       justify = c("left", "right", "centre", "none"),
       width = NULL, na.encode = TRUE, scientific = NA,
       big.mark   = "",   big.interval = 3L,
       small.mark = "", small.interval = 5L,
       decimal.mark = getOption("OutDec"),
       zero.print = NULL, drop0trailing = FALSE, &#8230;)</p><p># S3 method for data.frame
format(x, &#8230;, justify = "none")</p><p># S3 method for factor
format(x, &#8230;)</p><p># S3 method for AsIs
format(x, width = 12, &#8230;)</p>

Arguments

Parameter Deskripsi
x any R object (conceptually); typically numeric.
trim logical; if FALSE, logical, numeric and complex values are right-justified to a common width: if TRUE the leading blanks for justification are suppressed.
digits how many significant digits are to be used for numeric and complex x. The default, NULL, uses getOption("digits"). This is a suggestion: enough decimal places will be used so that the smallest (in magnitude) number has this many significant digits, and also to satisfy nsmall. (For the interpretation for complex numbers see signif.)
nsmall the minimum number of digits to the right of the decimal point in formatting real/complex numbers in non-scientific formats. Allowed values are 0 <= nsmall <= 20.
justify should a character vector be left-justified (the default), right-justified, centred or left alone. Can be abbreviated.
width default method: the minimum field width or NULL or 0 for no restriction. AsIs method: the maximum field width for non-character objects. NULL corresponds to the default 12.
na.encode logical: should NA strings be encoded? Note this only applies to elements of character vectors, not to numerical, complex nor logical NAs, which are always encoded as "NA".
scientific Either a logical specifying whether elements of a real or complex vector should be encoded in scientific format, or an integer penalty (see options("scipen")). Missing values correspond to the current default penalty.
&#8230; further arguments passed to or from other methods.
big.mark, big.interval, small.mark, small.interval, decimal.mark, zero.print, drop0trailing used for prettying (longish) numerical and complex sequences. Passed to prettyNum: that help page explains the details.

Return Value

Objek dengan struktur yang mirip dengan x berisi representasi karakter elemen argumen pertama x dalam format umum, dan dalam pengkodean lokal saat ini. Untuk karakter, numerik, kompleks, atau faktor x, dim dan dimname dipertahankan pada matriks/array dan nama pada vektor: tidak ada atribut lain yang disalin. Jika x adalah sebuah daftar, hasilnya adalah vektor karakter yang diperoleh dengan menerapkan format.default(x, …) ke setiap elemen daftar (setelah elemen yang tidak terdaftar yang merupakan daftar itu sendiri), dan t

Details

format adalah fungsi generik. Selain metode yang dijelaskan di sini, terdapat metode untuk tanggal (lihat format.Tanggal), tanggal-waktu (lihat format.POSIXct) dan untuk kelas lain seperti format.octmode dan format.dist. format.data.frame memformat bingkai data kolom demi kolom, menerapkan metode format yang sesuai untuk setiap kolom. Metode untuk kolom sering kali mirip dengan as.character tetapi menawarkan kontrol lebih besar. Kolom matriks dan bingkai data akan dikonversi menjadi kolom terpisah di hasil, dan kolom karakter (biasanya semua) akan diberi kelas "AsIs". format.factor mengonversi faktor menjadi vektor karakter dan kemudian memanggil metode default (dan justify berlaku). format.AsIs berkaitan dengan kolom objek rumit yang telah diekstraksi dari bingkai data. Objek karakter dan (atom) ma

Contoh

Example
R
# NOT RUN {
format(1:10)
format(1:10, trim = TRUE)

zz <- data.frame("(row names)"= c("aaaaa", "b"), check.names = FALSE)
format(zz)
format(zz, justify = "left")

## use of nsmall
format(13.7)
format(13.7, nsmall = 3)
format(c(6.0, 13.1), digits = 2)
format(c(6.0, 13.1), digits = 2, nsmall = 1)

## use of scientific
format(2^31-1)
format(2^31-1, scientific = TRUE)

## a list
z <- list(a = letters[1:3], b = (-pi+0i)^((-2:2)/2), c = c(1,10,100,1000),
          d = c("a", "longer", "character", "string"),
          q = quote( a + b ), e = expression(1+x))
## can you find the "2" small differences?
(f1 <- format(z, digits = 2))
(f2 <- format(z, digits = 2, justify = "left", trim = FALSE))
f1 == f2 ## 2 FALSE, 4 TRUE

## A "minimal" format() for S4 objects without their own format() method:
cc <- methods::getClassDef("standardGeneric")
format(cc) ## "<S4 class ......>"
# }

See Also

format.info indicates how an atomic vector would be formatted. formatC paste as.character sprintf print prettyNum toString encodeString.