# Sepal.Length Sepal.Width Petal.Length Petal. # Merc 450SLC 15.2 8 275.8 180 3.07 3.78 18.0 0 0 3 3Īnd, another example, using the iris dataset searching for the string osa: irisSubset <- iris It takes patterns and data as main arguments and returns a vector of the indices of the input vector elements. # Merc 280 19.2 6 167.6 123 3.92 3.44 18.3 1 0 4 4 The grep () in R is a built-in function that searches for matches to argument patterns within each element of a character vector. Mpg cyl disp hp drat wt qsec vs am gear carb Here's an example with the mtcars dataset, where we are matching all rows where the row names includes "Merc": mtcars If you don't want to load a package, you can try using grep() to search for the string you're matching. If that is what you had, then perhaps you had just mixed up row and column positions for subsetting data. r(e)d match 'r' (IF FOLLOWED BY 'e') then see if 'd' comes after 'r' The lookahead seeks 'e' only for the sake of matching 'r'. grep (), grepl (): Search for matches of a regular expression/pattern in a character vector. Note that the object does not have to be a data.table (but also remember that subsetting approaches for ames and data.tables are not identical): library(data.table) The primary R functions for dealing with regular expressions are. I don't know if that's a reference to the %like% from "data.table", but if it is, you can definitely use it as follows. I notice that you mention a function %like% in your current approach.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |