Was looking for predictors whose name starts with some substring, could not find any similar function.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
As added to
base
in 3.3.0,startsWith
(andendsWith
) are exactly this.https://stat.ethz.ch/R-manual/R-devel/library/base/html/startsWith.html
Not inbuilt like that.
Options include
grepl
andsubstr
.The dplyr package's
select
statement supportsstarts_with
andends_with
. For example, this selects the columns of the iris data frame that start withPetal
select
supports other subcommands too. Try?select
.This is relatively simple by using the substring function:
You cut each string to the desired length with substring. The length being the number of characters you are looking for at the beginning of each string.
The simplest way I can think of is to use the
%like%
operator:evaluates as
TRUE
- Starting with fevaluates as
TRUE
- Ending with oevaluates as
TRUE
- Containing aBorrowing some code from the
dplyr
package [see this] you could do something like this: