Title: | inSileco Miscellaneous Functions |
---|---|
Description: | A set of miscellaneous R functions written by our inSileco group. |
Authors: | Kevin Cazelles [aut, cre] |
Maintainer: | Kevin Cazelles <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.7.0.9000 |
Built: | 2025-03-24 03:52:20 UTC |
Source: | https://github.com/inSileco/inSilecoMisc |
Adjust the size of character strings by adding extra characters. It allows to constraint the size of the string or to add a specific number of extra characters.
adjustStrings( x, n, extra = 0, align = c("right", "left", "center"), add = FALSE )
adjustStrings( x, n, extra = 0, align = c("right", "left", "center"), add = FALSE )
x |
a character vector, or a vector to be coerced to a character vector. |
n |
a positive integer indicating the size of character strings to be created or added. |
extra |
a character vector, or a vector to be coerced to a character vector that will be (partially) added to produced a string of a specific length. |
align |
either "right", "left" or "center". If "right", then strings
will be right-aligned and so |
add |
a logical should |
This function was originally created to help getting a fixed number of digits when naming files. The current version is more general, it allows to add any string before or after to adjust the size. Not that if a character is longer than expected, it will be adequately cut off.
A character vector of the concatenated characters.
paste0('myfilename', adjustStrings(c(1:2,10,100), 3)) adjustStrings('# Comment ', 20, '#', align = "left")
paste0('myfilename', adjustStrings(c(1:2,10,100), 3)) adjustStrings('# Comment ', 20, '#', align = "left")
aggregateCol()
performs summary statistics on a specific subset of columns.
aggregateCol(data, grp, names_aggreg = NULL, FUN = sum, ...)
aggregateCol(data, grp, names_aggreg = NULL, FUN = sum, ...)
data |
a data frame. |
grp |
an integer vector, one value per |
names_aggreg |
column names for aggregated columns. |
FUN |
a function to be applied to all groups of columns. |
... |
further arguments to be passed to |
grp
is an integer vector, whose length is the number of columns of the
input data frame, is used to assign a group to each column that explicit the
sub-setting. Furthermore columns can be either kept as is using 0
or
discarded using NA
.
A data frame with the grouped columns.
stats::aggregate()
base::split
mat1 <- matrix(1:70,10) grp1 <- c(NA,0, 1, 1, 2, 2, 2) aggregateCol(mat1, grp1, FUN = mean)
mat1 <- matrix(1:70,10) grp1 <- c(NA,0, 1, 1, 2, 2, 2) aggregateCol(mat1, grp1, FUN = mean)
Apply a function on a given set of elements of a character string.
applyString(x, FUN, pos = NULL, pattern = NULL)
applyString(x, FUN, pos = NULL, pattern = NULL)
x |
a character vector, or a vector to be coerced to a character vector. |
FUN |
the function to be applied, see |
pos |
a vector indicating the elements position. |
pattern |
a pattern see |
A character vector.
In case both pos
or pattern
, the latter is ignored.
applyString('cool', pos = 1:2, FUN = toupper) applyString(c('cool', 'pro'), pattern = 'o', FUN = toupper)
applyString('cool', pos = 1:2, FUN = toupper) applyString(c('cool', 'pro'), pattern = 'o', FUN = toupper)
Assign a class to a set of column of a data frame. This function is designed to ease the changes of column's class of a given data frame.
assignClass2df(x, colid, cls)
assignClass2df(x, colid, cls)
x |
a data frame or a R object to be coerced into a data frame. |
colid |
the identity of columns for which class are ti be changed. |
cls |
a character vector containing the classes' names to be used in the
same order as |
A data frame for which columns have the required classes.
df1 <- matrix(signif(runif(20),4), ncol=2) df2 <- assignClass2df(df1, 2, 'character') str(df1) str(df2)
df1 <- matrix(signif(runif(20),4), ncol=2) df2 <- assignClass2df(df1, 2, 'character') str(df1) str(df2)
This function aims to assign an id to factor or similar character
strings. Regarding factors, as.integer()
does such task but the order
obtained may differ.
assignIds(x, alphabetical = FALSE)
assignIds(x, alphabetical = FALSE)
x |
an R object to be coerced into character type. |
alphabetical |
a logical indicating whether an alphabetical sorting must be applied. |
A vector of Ids.
assignIds(list(2,'f', 'd', 'f'))
assignIds(list(2,'f', 'd', 'f'))
Assigns a category to each element of a vector for a given set of threshold values.
categorize(x, categ, lower = FALSE)
categorize(x, categ, lower = FALSE)
x |
a numeric, complex, character or logical vector. |
categ |
a set of threshold values used to assign categories. |
lower |
a logical. If |
A vector of categories assigned.
categorize(stats::runif(40), categ=c(0.5,0.75)) categorize(LETTERS[1:5], categ='C') categorize(LETTERS[1:5], categ='C', lower=TRUE) categorize(LETTERS[floor(5*stats::runif(20))+1], categ=LETTERS[1:5], lower=TRUE)
categorize(stats::runif(40), categ=c(0.5,0.75)) categorize(LETTERS[1:5], categ='C') categorize(LETTERS[1:5], categ='C', lower=TRUE) categorize(LETTERS[floor(5*stats::runif(20))+1], categ=LETTERS[1:5], lower=TRUE)
Paste element and add elememt separators.
commaAnd(x, comma = ", ", and = " and ")
commaAnd(x, comma = ", ", and = " and ")
x |
vector of to be coerced to character strings (see |
comma |
element separator. |
and |
last element separator (for 3 elements in |
commaAnd(c("Judith", "Peter", "Rebecca"))
commaAnd(c("Judith", "Peter", "Rebecca"))
This function handles the creation of data frames based on intuitive parameters. It was originally designed to make row binding easier when columns differs among data frame by creating data frames with the same columns.
dfTemplate(cols, nrows = 1, col_classes = NULL, fill = NA) dfTemplateMatch(x, y, yonly = FALSE, order = FALSE, ...)
dfTemplate(cols, nrows = 1, col_classes = NULL, fill = NA) dfTemplateMatch(x, y, yonly = FALSE, order = FALSE, ...)
cols |
either a number of column or a vector of character used as columns names of the data frame to be returned. |
nrows |
row number. |
col_classes |
vector of column classes for the desired data frame.
By default, the class is determined by |
fill |
character or number used to fill out the columns. Default is |
x |
a data frame. |
y |
a data frame or a vector of strings use to specifies column names to be included in the data frame. |
yonly |
a logical. Should only |
order |
a logical. Should column of the output data frame be ordered
according to the template. Not that if there are more columns in |
... |
further arguments to be passed to |
Returns a data frame with the desired characteristics.
dfTemplateMatch()
: Returns a data frame that includes all columns specifies in y
.
dfTemplate(5, 2) dfTemplate(5, 2, col_classes = "character") dfA <- data.frame(col1 = c(1, 2), col2 = LETTERS[1:2]) dfB <- data.frame(col4 = c(1, 2), col2 = LETTERS[1:2]) dfTemplateMatch(dfA, c("col4", "col2")) dfTemplateMatch(dfA, c("col4", "col2"), yonly = TRUE) dfTemplateMatch(dfA, dfB, yonly = TRUE, order = TRUE)
dfTemplate(5, 2) dfTemplate(5, 2, col_classes = "character") dfA <- data.frame(col1 = c(1, 2), col2 = LETTERS[1:2]) dfB <- data.frame(col4 = c(1, 2), col2 = LETTERS[1:2]) dfTemplateMatch(dfA, c("col4", "col2")) dfTemplateMatch(dfA, c("col4", "col2"), yonly = TRUE) dfTemplateMatch(dfA, dfB, yonly = TRUE, order = TRUE)
Duplicates rows and columns of a given a data frame.
duplicateRow(x, id.el = 1, times = 1, append = FALSE) duplicateCol(x, id.el = 1, times = 1, append = FALSE)
duplicateRow(x, id.el = 1, times = 1, append = FALSE) duplicateCol(x, id.el = 1, times = 1, append = FALSE)
x |
a data frame. |
id.el |
identity of the elements to be duplicated. |
times |
number of times elements are duplicated. Could be a vector of the same length as |
append |
A logical. If |
returns a data frame with duplicated rows.
duplicateCol()
: returns a data frame with duplicated columns.
data(iris, package = "datasets") iris2 <- duplicateRow(iris, id.el = 1:50, times = 2) iris3 <- duplicateCol( iris, id.el = c("Petal.Length", "Petal.Width"), times = c(1, 2), append = TRUE)
data(iris, package = "datasets") iris2 <- duplicateRow(iris, id.el = 1:50, times = 2) iris3 <- duplicateCol( iris, id.el = c("Petal.Length", "Petal.Width"), times = c(1, 2), append = TRUE)
Given a set of values and a vector where the values must be found,
findThem
records the matched values and the position in the vector
where the values have been searched for.
findThem(what, where, todf = FALSE, reportnomatch = FALSE)
findThem(what, where, todf = FALSE, reportnomatch = FALSE)
what |
a vector a values to be searched for. |
where |
a vector where values will be searched on. |
todf |
a logical. Should the output object must be a data frame? |
reportnomatch |
a logical. If |
A list indicating matched positions for each elements of what
. If no match
is found then NA
is returned. If todf
is TRUE
then a three-columns data
frame is returned including values and positions in both what
and where
vectors.
x <- stats::rpois(1000,10) findThem(c(10,4,100), x) findThem(c(10,4,100), x, todf=TRUE) findThem(c(10,4,100), x, todf=TRUE, reportnomatch=TRUE)
x <- stats::rpois(1000,10) findThem(c(10,4,100), x) findThem(c(10,4,100), x, todf=TRUE) findThem(c(10,4,100), x, todf=TRUE, reportnomatch=TRUE)
The gaussianShape()
function computes a personnalisable Gaussian function.
Default values are the same as in stats::dnorm()
.
gaussianShape(x, optx = 0, opty = 1/sqrt(2 * pi), width = 1, pow = 2)
gaussianShape(x, optx = 0, opty = 1/sqrt(2 * pi), width = 1, pow = 2)
x |
a numeric vector. |
optx |
x-values at which the maximum is reached. |
opty |
extremum value. |
width |
width of the bell. |
pow |
a real number. |
A vector containing values standing for categories into which elements of x have fallen.
gaussianShape(0) plot(gaussianShape(1:1000, 500, 2, 250, pow=5), type='l')
gaussianShape(0) plot(gaussianShape(1:1000, 500, 2, 250, pow=5), type='l')
This function extracts all digits found in character vector and returns them as a list.
getDigits(x, collapse = NULL)
getDigits(x, collapse = NULL)
x |
a character vector where digits are sought, or an object which can be coerced by |
collapse |
an optional character string to separate the results (see [base::paste()). |
A list of digits.
getDigits('txt012-34')
getDigits('txt012-34')
Extract file name, extension and basename ofrom a path.é
getExtension(x, sep = .Platform$file.sep) getFilename(x, sep = .Platform$file.sep) getName(x, sep = .Platform$file.sep) getBasename(x, sep = .Platform$file.sep) getLocation(x, sep = .Platform$file.sep) getDetails(x, sep = .Platform$file.sep)
getExtension(x, sep = .Platform$file.sep) getFilename(x, sep = .Platform$file.sep) getName(x, sep = .Platform$file.sep) getBasename(x, sep = .Platform$file.sep) getLocation(x, sep = .Platform$file.sep) getDetails(x, sep = .Platform$file.sep)
x |
a character string. Note that |
sep |
file separator, default used the platform-specific file separator see |
For more functionalities, have a look at package fs.
Extract the file extension a character string (e.g. a path).
getFilename()
: Extract the file name from a character string, that is the base name and the file extension
getName()
: Extract the name of a file or a directory from a character string.
getBasename()
: Extract the base name of a file from a character string.
getLocation()
: Extract the location of the parent folfder from a character string.
getDetails()
: Return a data frame with basic information for all elements of a vector of paths.
getExtension("path1/path2/foo.R") getFilename("path1/path2/foo.R") getBasename("path1/path2/foo.R") getLocation("path1/path2/foo.R") getDetails("path1/path2/foo.R") getDetails(list.files(recursive = TRUE)) getExtension("foo.R") getBasename("foo.R")
getExtension("path1/path2/foo.R") getFilename("path1/path2/foo.R") getBasename("path1/path2/foo.R") getLocation("path1/path2/foo.R") getDetails("path1/path2/foo.R") getDetails(list.files(recursive = TRUE)) getExtension("foo.R") getBasename("foo.R")
Select words or letters based on their position in character strings.
keepWords( str, slc = 1, collapse = " ", na.rm = FALSE, split_words = "[[:punct:][:space:]]+" ) keepLetters( str, slc = 1, collapse = "", na.rm = FALSE, rm_punct = "[[:punct:][:space:]]+" ) keepInitials(str, split_words = "[\n\t\r\f\b[:punct:] ]+", collapse = "") wordCount(str, split_words = "[[:punct:][:space:]]+")
keepWords( str, slc = 1, collapse = " ", na.rm = FALSE, split_words = "[[:punct:][:space:]]+" ) keepLetters( str, slc = 1, collapse = "", na.rm = FALSE, rm_punct = "[[:punct:][:space:]]+" ) keepInitials(str, split_words = "[\n\t\r\f\b[:punct:] ]+", collapse = "") wordCount(str, split_words = "[[:punct:][:space:]]+")
str |
an input character vector (or a list) from which words will be extracted. |
slc |
a vector of integer indicating the selected positions of the words (or letters) to be kept. |
collapse |
character string used to separate selected words (or
letters), if |
na.rm |
a logical. Should missing values be removed? |
split_words |
a character string containing a regular expression used to split words. |
rm_punct |
a character string containing a regular expression used to remove punctuation characters. |
A vector (or a list) of the selected words.
keepLetters()
: A vector (or a list) of the selected letters.
keepInitials()
: A vector (or a list) of initials.
wordCount()
: A vector of the number of words for every character
strings passed as an input.
keepWords(loremIpsum(), 1:3) keepWords(c(loremIpsum(),'Another character string!'), slc = c(1,4)) keepWords(c(loremIpsum(),'A second character string.'), slc = c(1,4), na.rm = TRUE, collapse = '/') strex <- c('Lorem ipsum', 'dolor sit', ' amet;') keepLetters(strex, c(1,4)) keepLetters(strex, c(1,4), collapse = "") keepInitials("National Basketball Association") wordCount(c("two words!", "... and three words")) wordCount(loremIpsum())
keepWords(loremIpsum(), 1:3) keepWords(c(loremIpsum(),'Another character string!'), slc = c(1,4)) keepWords(c(loremIpsum(),'A second character string.'), slc = c(1,4), na.rm = TRUE, collapse = '/') strex <- c('Lorem ipsum', 'dolor sit', ' amet;') keepLetters(strex, c(1,4)) keepLetters(strex, c(1,4), collapse = "") keepInitials("National Basketball Association") wordCount(c("two words!", "... and three words")) wordCount(loremIpsum())
The logisic
function describe the classical logistic function,
logistic(x, yneg = -1, ypos = 1, lambda = 1, pow = 1) logistic2(x, yneg = -1, ypos = 1, lambda = 1, pow = 1, yzer = 0)
logistic(x, yneg = -1, ypos = 1, lambda = 1, pow = 1) logistic2(x, yneg = -1, ypos = 1, lambda = 1, pow = 1, yzer = 0)
x |
a numerical vector. |
yneg |
asymptotic values when x tends to |
ypos |
asymptotic values when y tends to |
lambda |
scalar coefficient. |
pow |
x exponent. |
yzer |
values (for |
The classic logistic equation is:
A slightly different version is:
A numeric vector.
logistic2()
: A slightly different logistic function.
https://en.wikipedia.org/wiki/Logistic_functionwikipedia.org/wiki/Logistic_function
Returns a common form of the Lorem ipsum text an optionally a subset of it.
loremIpsum(n = NULL)
loremIpsum(n = NULL)
n |
the number of words to be kept. |
A character string with the desired piece of lorem ipsum.
https://en.wikipedia.org/wiki/Lorem_ipsum
loremIpsum(5)
loremIpsum(5)
This function is a simple moving window function.
meanAlong(vec, n)
meanAlong(vec, n)
vec |
a vector of numeric. |
n |
an integer indicating the size of the window. |
meanAlong(1:10, 2)
meanAlong(1:10, 2)
Convenient wrappers around message()
to sent styled notices to the user
while a function/script is being executed.
msgInfo(..., appendLF = TRUE) msgError(..., appendLF = TRUE) msgSuccess(..., appendLF = TRUE) msgWarning(..., appendLF = TRUE)
msgInfo(..., appendLF = TRUE) msgError(..., appendLF = TRUE) msgSuccess(..., appendLF = TRUE) msgWarning(..., appendLF = TRUE)
... |
text to be passed to |
appendLF |
a logical. Should messages given as a character string have a new line appended ? |
Reports an info.
msgError()
: Reports an Error.
msgSuccess()
: Reports a success.
msgWarning()
: Reports a warning.
All of these functions call message()
, so for any function FUN()
using #' them, suppressMessages(FUN())
is sufficient to mute all messages.
msgInfo("computing") msgSuccess("done") msgError("you got it wrong") msgWarning("be careful")
msgInfo("computing") msgSuccess("done") msgError("you got it wrong") msgWarning("be careful")
Seek all elements matching a given pattern in a character strings.
multiMatch(text, pattern)
multiMatch(text, pattern)
text |
a character vector where matches are sought, or an object which
can be coerced by as.character to a character vector, see |
pattern |
character string containing a regular expression to be
matched in the given character vector, see |
multiMatch
is essentially a wrapper around base::regexec()
and
base::regmatches()
to find more than one match.
A vector of character strings matching pattern
argument.
multiMatch(loremIpsum(), " [[:alnum:]]{3} ")
multiMatch(loremIpsum(), " [[:alnum:]]{3} ")
Get a data frame of package and their installed version.
packagesUsed(vc_pkg)
packagesUsed(vc_pkg)
vc_pkg |
a vector of string characters including package names to be added. |
A data frame of two columns. First is the name of the package; second the version installed.
packagesUsed(c('utils', 'methods'))
packagesUsed(c('utils', 'methods'))
Reads YAML headers (typically found in Markdown files).
readYamlHeader(con)
readYamlHeader(con)
con |
connection object or a character string. |
A named list, see yaml::yaml.load()
for more details.
This function finds old names and replace them with new ones.
rename(x, old, new)
rename(x, old, new)
x |
an object from which names can be extracted see |
old |
a vector of character strings of old names. |
new |
a vector of character strings of new names. |
tb <- data.frame(var1 = 2, var2 = "B") rename(tb, "var1", "uptake") rename(tb, c("var1", "var2"), c("uptake", "type"))
tb <- data.frame(var1 = 2, var2 = "B") rename(tb, "var1", "uptake") rename(tb, c("var1", "var2"), c("uptake", "type"))
This function maps a set of values to a range of integers (from 1 to a positive integer passed as an argument).
scaleWithin(x, n = 100, mn = min(x), mx = max(x))
scaleWithin(x, n = 100, mn = min(x), mx = max(x))
x |
a numeric object of type |
n |
an integer designing The number of scaled values (between 1 and |
mn |
minimum value ( |
mx |
maximum value ( |
This function was originally created to ease the creation of custom color
scales. In such context, it is common practice to define a minium and a
maximum for the set of values to be displayed values as well as a number of
color to be used in the color scale (n
). This is exactly what
scaleWithin()
does: minimum and maximum are by default the ones of the set
of values x
but can also be set using mn
and mx
in which case values
below mn
will be set to mn
(and thus to 1 in the output) and values
above mx
will be set to mx
(and thus to 1 in the output). Finally, the
number of colors to be used used in is given by n
.
A numeric vector
x <- stats::rpois(20, 20) scaleWithin(x, 20, 10, 30) scaleWithin(matrix(x, 10, 2), mn = 20, mx = 30)
x <- stats::rpois(20, 20) scaleWithin(x, 20, 10, 30) scaleWithin(matrix(x, 10, 2), mn = 20, mx = 30)
Generate a regular sequence based on the range of a vector
seqRg(x, n, offset = 0, prop = TRUE) seqCol(df) seqRow(df)
seqRg(x, n, offset = 0, prop = TRUE) seqCol(df) seqRow(df)
x |
a vector. |
n |
the number of values in the output sequence. |
offset |
extend or reduce the range . |
prop |
a logical. If |
df |
a data frame or a matrix. |
seqCol()
: a regular sequence based on the number of columns in a data frame.
seqRow()
: a regular sequence based on the number of rows in a data frame.
seqRg(runif(10), 10) seqRg(1:10, 10, .5) seqCol(matrix(1, 3, 2))
seqRg(runif(10), 10) seqRg(1:10, 10, .5) seqCol(matrix(1, 3, 2))
This function is designed to ease the changes of column's class of a given data frame.
setColClass(x, colid, cls)
setColClass(x, colid, cls)
x |
a data frame or an R object to be coerced into a data frame. |
colid |
the identity of columns for which class are to be changed. |
cls |
a character vector containing the classes' names to be used in the
same order as |
A data frame whose columns have the desired classes.
df1 <- matrix(signif(runif(20),4), ncol=2) df2 <- setColClass(df1, 2, 'character') str(df1) str(df2)
df1 <- matrix(signif(runif(20),4), ncol=2) df2 <- setColClass(df1, 2, 'character') str(df1) str(df2)
The signifSymbols
function takes one vector of p-values and returns
a vector of symbols that correspond to thresholds that can be set. Default
thresholds values and symbols are the most common ones.
signifSymbols( pvalue, thresholds = c(0.1, 0.05, 0.01, 0.001), symbols = c(".", "*", "**", "***"), notsignif = "n.s." )
signifSymbols( pvalue, thresholds = c(0.1, 0.05, 0.01, 0.001), symbols = c(".", "*", "**", "***"), notsignif = "n.s." )
pvalue |
a p-value for which a symbol is requested. |
thresholds |
the threshold values that define category to which symbols are assigned. |
symbols |
list of symbols. |
notsignif |
symbols for non significant p-value. |
signifSymbols(.012) signifSymbols(.008) lapply(c(.2, .08, .04, .008, 0.0001), signifSymbols)
signifSymbols(.012) signifSymbols(.008) lapply(c(.2, .08, .04, .008, 0.0001), signifSymbols)
Add missing rows or columns based on names and Duplicates rows and columns of a given a data frame.
squaretize(x, fill = 0, reorder = TRUE)
squaretize(x, fill = 0, reorder = TRUE)
x |
an object to be coerced into matrix. |
fill |
character string used to fill the additional rows and/or columns. |
reorder |
a logical. Should names must be used to order rows and columns? |
A square matrix.
mat <- matrix(1:12, 3, 4) mat2 <- squaretize(mat) matb <- matrix(1:12, 4, 3) colnames(matb) <- LETTERS[1:3] mat2b <- squaretize(matb)
mat <- matrix(1:12, 3, 4) mat2 <- squaretize(mat) matb <- matrix(1:12, 4, 3) colnames(matb) <- LETTERS[1:3] mat2b <- squaretize(matb)
Timer and Stopwatch
stopwatch(max_time = 1000, pause = 0.01, digits = 5) timer(time, pause = 0.01, digits = 5)
stopwatch(max_time = 1000, pause = 0.01, digits = 5) timer(time, pause = 0.01, digits = 5)
max_time |
time in seconds after which the stopwatch is forced to stop, use |
pause |
time duration of the pause between 2 time increments displayed (it should better be small). |
digits |
number of digits displayed. |
time |
initial time (in seconds) for the timer. |
timer()
: Timer
## Not run: stopwatch(10) stopwatch(20) ## End(Not run)
## Not run: stopwatch(10) stopwatch(20) ## End(Not run)
Write a data frame or a list of data frames in a markdown document converted #' in various format using pandoc.
tblDown( x, output_file = "./tables.docx", section = NULL, caption = NULL, title = NULL, row.names = FALSE, ... )
tblDown( x, output_file = "./tables.docx", section = NULL, caption = NULL, title = NULL, row.names = FALSE, ... )
x |
a data frame or a list of data frames. |
output_file |
path to the output file. Its extension will be used by pandoc to correctly render the final document in the write format. |
section |
a vector of character strings used as section titles (optional). |
caption |
a vector of character strings used as captions (optional). |
title |
a character string used as a title for the document (optional). |
row.names |
a logical. Should row names be added? See |
... |
further arguments passed to |
This function calls base::cat()
and knitr::kable()
to write a Markdown
document containing a list of tables that is then converted into the
desired format. For section
and caption
if the length differ then
will be cut off or expanded.
A data frame whose columns have the desired classes.
https://pandoc.org/MANUAL.html#tables
## Not run: data(CO2) tblDown(list(CO2[1:2, ], CO2[3:6,]), section = "section") tblDown(list(CO2[1:2, ], CO2[3:6,]), "./tables.pdf") ## End(Not run)
## Not run: data(CO2) tblDown(list(CO2[1:2, ], CO2[3:6,]), section = "section") tblDown(list(CO2[1:2, ], CO2[3:6,]), "./tables.pdf") ## End(Not run)
Search values or patterns in a vector.
whichIs(x, y, isPattern = FALSE, ...)
whichIs(x, y, isPattern = FALSE, ...)
x |
a vector of values or patterns to be searched for. |
y |
a vector where x values are searched for. |
isPattern |
should x be considered as a vector of patterns? |
... |
further arguments to be passed to |
A list of positions. Each element corresponds to the matches for a specific x value.
vec <- LETTERS[1:10] spl <- sample(vec) id <- unlist(whichIs(vec, spl)) identical(vec, spl[id])
vec <- LETTERS[1:10] spl <- sample(vec) id <- unlist(whichIs(vec, spl)) identical(vec, spl[id])