[R] how to extract strings in any column and in any row that start with
Abby Spurdle
@purd|e@@ @end|ng |rom gm@||@com
Fri May 15 23:42:07 CEST 2020
> How would I extract from it all strings that start with E10?
Hi Ana,
Here's a simple solution:
x <- c ("P24601", "E101", "E102", "3.141593",
"E101", "xE101", "e103", " E104 ")
x [substring (x, 1, 3) == "E10"]
You' will need to replace x with another *character vector*.
(As touched on earlier, a data.frame may cause some problems).
Here's some variations:
unique (x [substring (x, 1, 3) == "E10"])
y <- toupper (x)
y [substring (y, 1, 3) == "E10"]
y <- trimws (x)
y [substring (y, 1, 3) == "E10"]
More information about the R-help
mailing list