search for: grepl

Displaying 20 results from an estimated 287 matches for "grepl".

Did you mean: grep
2016 Apr 24
1
assign color to subsets
'grepl' returns a logical vector; you have to use this to get your subset. You can use: df_tq <- subset(df, grepl("t1", Command)) df_t2 <- subset(df, grepl("t2", Command)) # if you want to also get a subset that has both, use df_both <- subset(df, grepl("t1",...
2016 Apr 24
0
assign color to subsets
now after this: df_both <- subset(df, grepl("t1", Command) & grepl("t2", Command)) I use factor to apply the subset to df but then the Command level becomes 0 df_both$Command=factor(df_both$Command) str(df_both) $ Protocol : Factor w/ 0 levels: Do you know what is the reason? Thanks for replying...
2016 Apr 30
3
how to use AND in grepl
...:int 100,210,548,546,..... $Command :factor W/2229 levels "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"... I have tried this but I did not get result: t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command)) does anyone know how to apply AND in grepl? Thanks Elahe
2010 Oct 08
2
Memory management in R
Dear All, I am experiencing some problems with a script of mine. It crashes with this message Error in grepl(fut_string, past_string) : invalid regular expression '12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#12653a6#1265...
2016 Apr 10
0
what is the faster way to search for a pattern in a few million entries data frame ?
...F with millions of entries so > I was wondering how people are doing that in the faster way. I did this to generate and search 40 million unique strings > grams <- as.character(1:4e7) ## a long time passes... > system.time(grep("^900001", grams)) ## similar times to grepl user system elapsed 10.384 0.168 10.543 Is that the basic task you're trying to accomplish? grep(l) goes quickly to C, so I don't think data.table or other will be markedly faster if you're looking for an arbitrary regular expression (use fixed=TRUE if looking for an exact...
2019 Aug 09
3
Underscores in package names
...responding tarball name might be mypackage_2.3.1_2.3.2 after a > patch. Yes its a silly example, but why allow that kind of ambiguity? > > > > For the record @Ben Bolker <bbolker at gmail.com> > > Packages that mix case anywhere in their package name: > > > table(grepl("((^[a-z].*[A-Z])|(^[A-Z].*[a-z]))", row.names(a1))) > > > FALSE TRUE > > 8818 5932 > > > Packages which start with lower case and have at least one upper > > > table(grepl("((^[a-z].*[A-Z]))", row.names(a1))) > > > FALSE TRUE > &...
2023 Jan 14
2
Removing variables from data frame with a wile card
Thanks to all. Very helpful. Steven from iPhone > On Jan 14, 2023, at 3:08 PM, Andrew Simmons <akwsimmo at gmail.com> wrote: > > ?You'll want to use grep() or grepl(). By default, grep() uses extended > regular expressions to find matches, but you can also use perl regular > expressions and globbing (after converting to a regular expression). > For example: > > grepl("^yr", colnames(mydata)) > > will tell you which 'colname...
2023 May 30
3
why does [A-Z] include 'T' in an Estonian locale?
Inspired by this old Stack Overflow question https://stackoverflow.com/questions/19765610/when-does-locale-affect-rs-regular-expressions I was wondering why this is TRUE: Sys.setlocale("LC_ALL", "et_EE") grepl("[A-Z]", "T") TRE's documentation at <https://laurikari.net/tre/documentation/regex-syntax/> says that a range "is shorthand for the full range of characters between those two [endpoints] (inclusive) in the collating sequence". Yet, T is *not* between A...
2011 Jan 29
1
Subset using grepl
...uld like to subset a dataframe by using part of the level name. x <- rep(LETTERS[1:20],3) y <- rep(1:3, 20) z <- paste(x,y, sep="") random.data <- rnorm(60) data <- as.data.frame(cbind(z, random.data)) I need rows that contain the letters A to J, so I tried: subset(data, grepl(LETTERS[1:10], z)) # got only rows with A subset(data, z %in% LETTERS[1:10]) # got no rows I think I'm getting close to the solution but need a little bit of help here, thanks in advance. Kang Min
2013 Feb 05
2
R Regular Expressions - Metacharacters
I thought that I can use metacharacters such as \w to match word characters with one backslash. But for some reason, I need to include two backslashes. > grepl(pattern='\w', x="what") Error: '\w' is an unrecognized escape in character string starting "\w" > grepl(pattern='\\w', x="what") [1] TRUE I can't find the reason for this on the help pages. Does anyone know why? Thanks! [[alternativ...
2016 Apr 28
2
Combinaciones sin repetición...con restricciones
...1 al 7: datos <- c("a", "b", "c", "a,b", "a,c", "b,c", "a,b,c") df <- my_choice(datos, 1, 7) Ahora ya tengo un data frame con las 127 combinaciones posibles de los 7 objetos. El filtro del data frame lo hago con apply y grepl (lo intenté con str_detect, pero me daba problemas con las filas que tenían NA) Ejemplo: combinaciones que tengan los elementos a y b, pero no c df[apply(df, 1, function(x) any(grepl("a", x)) & any(grepl("b", x)) & all(!grepl("c", x))),] Ejemplo: combinacio...
2009 Nov 23
4
Check if string has all alphabets or numbers
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091123/470946bc/attachment-0001.pl>
2011 Jun 09
2
scatterplot3d - help assign colors based on multiple conditions
Hi I am relatively new to R and am trying to figure out to plot 3d scatter plot using defined colors based on x-axis and y-axis values. Right now in the code below, I assign colors based on certain values in the names of the x-axis. Now if I want to extend the condition to assign a color based on the names of both x-axis and y-axis values, what should I be doing? Any help or ideas would be
2023 Jan 14
1
Removing variables from data frame with a wile card
You'll want to use grep() or grepl(). By default, grep() uses extended regular expressions to find matches, but you can also use perl regular expressions and globbing (after converting to a regular expression). For example: grepl("^yr", colnames(mydata)) will tell you which 'colnames' start with "yr". I...
2016 Apr 22
0
subset by multiple letters condition
You can use the grepl() function to give you logicals for each criterion, then combine them as needed. For example: # example version of Command Command <- paste0("_localize_", c("PD","t2","t1_seq", "abc", "xyz", "PD_t1")) hasPD <- grepl(&quo...
2012 Feb 14
3
Wildcard for indexing?
Hi, I'd like to know if it is possible to use wildcards * for indexing... E.g. I have a vector of strings. Now I'd like to select all elements which start with A_*? I'd also need to combine that with logical operators: "Select all elements of a vector that start with A (A*) OR that start with B (B*)" Probably that is quite easy. I looked into grep() which I think might
2016 Apr 22
2
subset by multiple letters condition
Hi all, I have a data frame df and I want to do subset based on several conditions of letters of the names in Command.1)if the names contain PD 2)if the names contain t1 3)if the names contain t2 4)if the names contain t1 and PD 5)if the names contain t2 and PD 6)otherwise the names would be unknown. I don't know how to use grep for all these conditions. 'data.frame': 36919
2016 Apr 23
1
subset by multiple letters condition
Thanks Jean, Does anyone know how to set these [hast1] and [hast2] as the colors of a plot? On Friday, April 22, 2016 7:39 AM, "Adams, Jean" <jvadams at usgs.gov> wrote: You can use the grepl() function to give you logicals for each criterion, then combine them as needed. For example: # example version of Command Command <- paste0("_localize_", c("PD","t2","t1_seq", "abc", "xyz", "PD_t1")) hasPD <- grepl(&quo...
2017 Jun 29
0
Different date formats in one column
...an example of how this can be done. There are many tutorials on the internet that describe regular expressions... they are not unique to R. #----- dta <- read.table( text= "DtStr 020917 2/22/17 May-2-2015 May-12-15 ", header=TRUE, as.is=TRUE ) dta$Dt <- as.Date( NA ) idx <- grepl( "^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[0-9]+-[0-9]{4}$", dta$DtStr, perl=TRUE, ignore.case = TRUE ) dta$Dt[ idx ] <- as.Date( dta$DtStr[ idx ], format="%B-%d-%Y" ) idx <- grepl( "^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[0-9]+-[0-9]{2}$&qu...
2023 Feb 12
2
Removing variables from data frame with a wile card
...drop = FALSE], but some people don't >like that because it doesn't look like matrix indexing anymore. > > >On Sun, Feb 12, 2023, 17:18 Steven T. Yen <styen at ntu.edu.tw> wrote: > >> In the line suggested by Andrew Simmons, >> >> mydata <- mydata[, !grepl("^yr", colnames(mydata)), drop = FALSE] >> >> what does drop=FALSE do? Thanks. >> >> On 1/14/2023 8:48 PM, Steven Yen wrote: >> >> Thanks to all. Very helpful. >> >> Steven from iPhone >> >> On Jan 14, 2023, at 3:08 PM, Andrew Si...