Hi Rui,
thank you so much that is exactly what I needed!
Cheers,
Ana
On Fri, May 15, 2020 at 5:12 PM Rui Barradas wrote:
>
> Hello,
>
> I have tried several options and with large dataframes this one was the
> fastest (in my tests, of the ones I have tried).
>
>
> s1 <- sapply(tot, function(x)
Hello,
I have tried several options and with large dataframes this one was the
fastest (in my tests, of the ones I have tried).
s1 <- sapply(tot, function(x) grep('^E10', x, value = TRUE))
Then unlist(s1).
A close second (15% slower) was
s2 <- tot[sapply(tot, function(x) grepl('^E10',
> 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
This is almost certainly not the most efficient way:
tot <- data.frame(v1 = paste0(LETTERS[seq(1:5)],seq(1:10)),
v2 = paste0(LETTERS[seq(1:5)],seq(from = 101, to=110, by =
1)),
v3 = paste0(LETTERS[seq(1:5)],seq(from = 111, to=120, by =
1)),
v4 =
If you want to treat your data frame as if it were a vector, then convert it to
a vector before you give it to grep.
unlist(tot)
On May 15, 2020 12:24:17 PM PDT, Ana Marija wrote:
>Hello,
>
>this command was running for more than 2 hours
>grep("E10",tot,value=T)
>and no output
>
>and this
Hello,
this command was running for more than 2 hours
grep("E10",tot,value=T)
and no output
and this command
df1 <- tot %>% filter_all(any_vars(grepl( '^E10', .)))
gave me a subset (a data frame) of tot where ^E10
what I need is just a vector or all values in tot which start with E10.
Thanks
Read about regular expressions... they are extremely useful.
df1 <- tot %>% filter_all(any_vars(grepl( '^E10', .)))
It is bad form not to put spaces around the <- assignment.
On May 15, 2020 10:00:04 AM PDT, Ana Marija wrote:
>Hello,
>
>I have a data frame:
>
>> dim(tot)
>[1] 502536 1093
>
Hello,
I have a data frame:
> dim(tot)
[1] 502536 1093
How would I extract from it all strings that start with E10?
I know how to extract all rows that contain with E10
df0<-tot %>% filter_all(any_vars(. %in% c('E10')))
> dim(df0)
[1] 5105 1093
but I just need a vector of strings that start
8 matches
Mail list logo