1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 00:02:38 +02:00

support format.freq

This commit is contained in:
2018-07-16 16:41:48 +02:00
parent 6eaf33baf3
commit 715a7630ca
7 changed files with 113 additions and 18 deletions

View File

@ -7,9 +7,10 @@
\title{Import/export from clipboard}
\usage{
clipboard_import(sep = "\\t", header = TRUE, dec = ".", na = c("", "NA",
"NULL"), startrow = 1, as_vector = TRUE, guess_col_types = TRUE,
date_names = "en", date_format = "\%Y-\%m-\%d", time_format = "\%H:\%M",
tz = Sys.timezone(), encoding = "UTF-8", info = TRUE)
"NULL"), stringsAsFactors = FALSE, startrow = 1, as_vector = TRUE,
guess_col_types = TRUE, date_names = "en", date_format = "\%Y-\%m-\%d",
time_format = "\%H:\%M", tz = Sys.timezone(), encoding = "UTF-8",
info = TRUE)
clipboard_export(x, sep = "\\t", dec = ".", na = "", header = TRUE,
info = TRUE)
@ -30,6 +31,11 @@ clipboard_export(x, sep = "\\t", dec = ".", na = "", header = TRUE,
\item{na}{the string to use for missing values in the data.}
\item{stringsAsFactors}{logical: should character vectors be converted
to factors? The \sQuote{factory-fresh} default is \code{TRUE}, but
this can be changed by setting \code{\link{options}(stringsAsFactors
= FALSE)}.}
\item{startrow}{\emph{n}th row to start importing from. When \code{header = TRUE}, the import will start on row \code{startrow} \emph{below} the header.}
\item{as_vector}{a logical value indicating whether data consisting of only one column should be imported as vector using \code{\link[dplyr]{pull}}. This will strip off the header.}
@ -80,7 +86,11 @@ The data will be read and written as tab-separated by default, which makes it po
This also supports automatic column type transformation, with AMR classes \code{\link{as.rsi}} and \code{\link{as.mic}}.
}
\details{
\if{html}{
The parameter \code{stringsAsFactors} defaults to \code{FALSE}, as opposed to most base \R methods.
The parameters \code{date_format} and \code{time_format} also support generic date and time formats like \code{"dd-mm-yyyy"} like Excel.
\if{html}{
\strong{Example for copying from Excel:}
\out{<div style="text-align: left">}\figure{clipboard_copy.png}\out{</div>}
\cr
@ -96,6 +106,23 @@ This also supports automatic column type transformation, with AMR classes \code{
\out{<div style="text-align: left">}\figure{clipboard_rsi.png}\out{</div>}
}
}
\examples{
\dontrun{
df1 <- data.frame(a = letters[1:12],
b = runif(n = 12, min = 1000, max = 2000),
stringsAsFactors = FALSE)
clipboard_export(df1)
df2 <- clipboard_import()
identical(df1, df2)
# send frequency table to clipboard (e.g. for pasting in Excel)
septic_patients \%>\%
freq(age) \%>\%
format() \%>\% # this will format the percentages
clipboard_export()
}
}
\keyword{clipboard}
\keyword{clipboard_export}
\keyword{clipboard_import}

View File

@ -111,10 +111,13 @@ years <- septic_patients \%>\%
# show only the top 5
years \%>\% print(nmax = 5)
# save to an object with formatted percentages
years <- format(years)
# print a histogram of numeric values
septic_patients \%>\%
freq(age) \%>\%
hist() # prettier: ggplot(septic_patients, aes(age)) + geom_histogram()
hist() # prettier: ggplot(septic_patients, aes(age)) + geom_histogram()
# or print all points to a regular plot
septic_patients \%>\%
@ -135,13 +138,20 @@ identical(septic_patients \%>\%
freq(age) \%>\%
as.vector() \%>\%
sort(),
sort(septic_patients$age)
) # TRUE
sort(septic_patients$age)) # TRUE
# also supports table:
# it also supports `table` objects:
table(septic_patients$sex,
septic_patients$age) \%>\%
freq()
freq(sep = " **sep** ")
\dontrun{
# send frequency table to clipboard (e.g. for pasting in Excel)
septic_patients \%>\%
freq(age) \%>\%
format() \%>\% # this will format the percentages
clipboard_export()
}
}
\keyword{freq}
\keyword{frequency}