Re: [R] grep

2024-07-13 Thread Steven Yen
Yes. Any of the following worked. The pipe greater than (|>) is neat! Thanks. > v<-goprobit.p$est > names(v) |> grep("somewhat|very", x = _)  [1]  6  7  8  9 10 11 12 13 28 29 30 31 32 33 34 35 50 51 52 53 54 55 56 57 > v |> names() |> grep("somewhat|very", x = _)  [1]  6  7  8  9 10 11 12 13

Re: [R] grep

2024-07-12 Thread Steven Yen
Now I've found another way to make it work. All I need is to pick up the names in the column (x.1.age...). > v<-pr(goprobit.p); v Maximum-Likelihood Estimates weighted = FALSE iterations = 5 logLik = -14160.75 finalHessian = TRUE Covariance matrix is Robust Number of parameters = 66 Sample

Re: [R] grep

2024-07-12 Thread Rui Barradas
Hello,l Though the question is already answered, here is another answer to what is 'x'. The output in the OP is not a lm or glm output but if your regression model was programmed according to recommended practices, there must be a 'coefficients' member in the list or object it returns and

Re: [R] grep

2024-07-12 Thread Jorgen Harmse via R-help
ist mailto:r-help@r-project.org>> Cc: Steven Yen mailto:sye...@gmail.com>> Subject: Re: [R] grep Message-ID: mailto:b73784ce-c018-4587-bcd9-64adbd0dc...@ntu.edu.tw>> Content-Type: text/plain; charset="utf-8" Sorry. grepl worked: which(gr

Re: [R] grep

2024-07-12 Thread Steven Yen
Sorry. grepl worked: which(grepl("very|somewhat",names(goprobit.p$est))) On 7/12/2024 5:34 PM, Steven Yen wrote: > > Could not get "which" to work, but my grep worked. Thanks. > > > which(grep("very|somewhat",names(goprobit.p$est))) Error in > which(grep("very|somewhat", names(goprobit.p$est)))

Re: [R] grep

2024-07-12 Thread Steven Yen
Could not get "which" to work, but my grep worked. Thanks. > which(grep("very|somewhat",names(goprobit.p$est))) Error in which(grep("very|somewhat", names(goprobit.p$est))) : argument to 'which' is not logical > grep("very|somewhat",names(goprobit.p$est)) [1] 6 7 8 9 10 11 12 13 28 29 30 31 32

Re: [R] grep

2024-07-12 Thread Steven Yen
Thanks. In this case below, what is "x"? I tried rownames(out) which did not work. Sorry. Does this sound like homework to you? On 7/12/2024 5:09 PM, Uwe Ligges wrote: On 12.07.2024 10:54, Steven Yen wrote: Below is part a regression printout. How can I use "grep" to identify rows headed

Re: [R] grep

2024-07-12 Thread Uwe Ligges
On 12.07.2024 10:54, Steven Yen wrote: Below is part a regression printout. How can I use "grep" to identify rows headed by variables (first column) with a certain label. In this case, I like to find variables containing "somewhath", "veryh", "somewhatm", "verym", "somewhatc",

[R] grep

2024-07-12 Thread Steven Yen
Below is part a regression printout. How can I use "grep" to identify rows headed by variables (first column) with a certain label. In this case, I like to find variables containing "somewhath", "veryh", "somewhatm", "verym", "somewhatc", "veryc","somewhatl", "veryl". The result should be an

Re: [R] grep

2022-07-10 Thread John Fox
Dear Steven, Beyond ?regex, the Wikipedia article on regular expressions is quite helpful and not too long. I hope this helps, John On 2022-07-10 9:43 p.m., Steven T. Yen wrote: Thanks Jeff. It works. If there is a good reference I should

Re: [R] grep

2022-07-10 Thread Andrew Simmons
?regex is a nice starting point, it's got plenty of details on meta characters and characters classes, if you need more advanced stuff you'll probably have to look at the perl regex documentation, I believe it's linked in ?regex. I might try something like grep("^[xz]\\.") or grep("^[xz][.]")

Re: [R] R grep question

2021-05-28 Thread Bert Gunter
FWIW: I think Jim makes an excellent point -- regex's really aren't the right tool for this sort of thing (imho); matching is. Note also that if one is willing to live with a logical response (better, again imho), then the ifelse() can of course be dispensed with: > CRC$MMR.gene<-CRC$gene.all

Re: [R] R grep question

2021-05-27 Thread Jim Lemon
Hi Kai, You may find %in% easier than grep when multiple matches are needed: match_strings<-c("MLH1","MSH2") CRC<-data.frame(gene.all=c("MLH1","MSL1","MSH2","MCC3")) CRC$MMR.gene<-ifelse(CRC$gene.all %in% match_strings,"Yes","No") Composing your match strings before applying %in% may be more

Re: [R] R grep question

2021-05-27 Thread Marc Schwartz via R-help
Hi, A quick clarification: The regular expression is a single quoted character vector, not a character vector on either side of the | operator: "MLH1|MSH2" not: "MLH1"|"MSH2" The | is treated as a special character within the regular expression. See ?regex. grep(), when value = FALSE,

Re: [R] R grep question

2021-05-27 Thread Kai Yang via R-help
Hi Rui,thank you for your suggestion.  but when I try the solution, I got message below: Error in "MLH1" | "MSH2" :   operations are possible only for numeric, logical or complex types does it mean, grepl can not work on character field? Thanks,KaiOn Thursday, May 27, 2021, 01:37:58 AM

Re: [R] R grep question

2021-05-27 Thread Rui Barradas
Hello, ifelse needs a logical condition, not the value. Try grepl. CRC$MMR.gene <- ifelse(grepl("MLH1"|"MSH2",CRC$gene.all), "Yes", "No") Hope this helps, Rui Barradas Às 05:29 de 27/05/21, Kai Yang via R-help escreveu: Hi List, I wrote the code to create a new variable:

Re: [R] R grep question

2021-05-27 Thread Jeff Newmiller
Post in plain text Use grepl On May 26, 2021 9:29:10 PM PDT, Kai Yang via R-help wrote: >Hi List, >I wrote the code to create a new variable: >CRC$MMR.gene<-ifelse(grep("MLH1"|"MSH2",CRC$gene.all,value=T),"Yes","No") >  > >I need to create MMR.gene column in CRC data frame, ifgene.all column

[R] R grep question

2021-05-26 Thread Kai Yang via R-help
Hi List, I wrote the code to create a new variable: CRC$MMR.gene<-ifelse(grep("MLH1"|"MSH2",CRC$gene.all,value=T),"Yes","No")   I need to create MMR.gene column in CRC data frame, ifgene.all column contenes MLH1 or MSH2, then the MMR.gene=Yes, if not,MMR.gene=No But, the code doesn't work for

Re: [R] grep

2021-05-09 Thread Rui Barradas
Hello, Maybe instead of a loop, vectorize with logical indices. i1 <- is.na(jindex) i2 <- is.numeric(jindex) if(any(!i1)){ if(any(!i2)){ words <- jindex[!i1 & !i2] pattern <- paste(words, collapse = "|") jindex <- grep(pattern = pattern, x.label, value = FALSE) } jj <-

Re: [R] grep

2021-05-08 Thread Steven Yen
Thank to Rui, Jeff, and Bert. They are all very useful. Somewhat related is the following, in which jindex is a numeric or alphanumeric vector in a function that starts with try<-function(, jindex=NA) In the if loop, in the first line I am trying to determine whether the vector jindex is

Re: [R] grep

2021-05-08 Thread Rui Barradas
Hello, The pattern can be assembled with paste(., collapse = "|"). With the same vector of names, nms: words <- c("black","conserv") pattern <- paste(words, collapse = "|") grep(pattern = pattern, nms, value = TRUE) #[1] "x1.black" "x1.conserv" "x2.black" "x2.conserv" Hope this helps,

Re: [R] grep

2021-05-08 Thread Jeff Newmiller
Regular expression patterns are not vectorized... only the data to be searched are. Use one of the many websites dedicated to tutoring regular expressions to learn how they work. (Using function names like "names" as data names is bad practice.) nms <- c( "x1.one", "x1.black", "x1.othrrace",

Re: [R] grep

2021-05-08 Thread David Winsemius
On 5/8/21 10:00 AM, Steven Yen wrote: Below, the first command simply creates a list of 16 names (labels) which can be ignore. In the 2nd and 3rd commands, I am able to identify names containing "black". In line 4, I am trying to identify names containing "black" or "conserv" but

[R] grep

2021-05-08 Thread Steven Yen
Below, the first command simply creates a list of 16 names (labels) which can be ignore. In the 2nd and 3rd commands, I am able to identify names containing "black". In line 4, I am trying to identify names containing "black" or "conserv" but obviously it does not work. Can someone help?

Re: [R] grep

2018-07-16 Thread Ista Zahn
grep("(^| )ABHD14A( ;|$)",xgen, value = TRUE) maybe. On Mon, Jul 16, 2018 at 1:46 PM, Brian Smith wrote: > Hi, > > I was trying to find a pattern ("ABHD14A") in a character string ('xgen' in > example below) using grepl. Note that the individual members may be > separated by a semi-colon. > >

[R] grep

2018-07-16 Thread Brian Smith
Hi, I was trying to find a pattern ("ABHD14A") in a character string ('xgen' in example below) using grepl. Note that the individual members may be separated by a semi-colon. The correct answer should return: "ABHD-ACY1 ; ABHD14A" "ABHD14A ; YYY" I have tried three approaches, but still seem a

Re: [R] Grep command

2016-05-19 Thread Joyce Robbins
I'm not sure you need grep: > all %in% some [1] TRUE FALSE TRUE FALSE FALSE TRUE On Thu, May 19, 2016 at 7:58 PM, MacQueen, Don wrote: > Start with: > > > all <- c("ants","birds","cats","dogs","elks","fox") > > all[grep('ants|cats|fox',all)] > [1] "ants" "cats" "fox" > >

Re: [R] Grep command

2016-05-19 Thread MacQueen, Don
Start with: > all <- c("ants","birds","cats","dogs","elks","fox") > all[grep('ants|cats|fox',all)] [1] "ants" "cats" "fox" Then construct the first arg to grep: > some <- c("ants","cats","fox") > all[ grep( paste(some,collapse='|') , all)] [1] "ants" "cats" "fox" -- Don MacQueen Lawrence

Re: [R] Grep command

2016-05-19 Thread David Winsemius
> On May 19, 2016, at 4:09 PM, Steven Yen wrote: > > What is a good way to grep multiple strings (say in a vector)? In the > following, I grep ants, cats, and fox separately and concatenate them, > is there a way to grep the trio in one action? Thanks. > >

Re: [R] Grep command

2016-05-19 Thread Peter Langfelder
I use my own functions multiGrep and multiGrepl: multiGrep = function(patterns, x, ..., sort = TRUE, invert = FALSE) { if (invert) { out = multiIntersect(lapply(patterns, grep, x, ..., invert = TRUE)) } else out = unique(unlist(lapply(patterns, grep, x, ..., invert = FALSE))); if

[R] Grep command

2016-05-19 Thread Steven Yen
What is a good way to grep multiple strings (say in a vector)? In the following, I grep ants, cats, and fox separately and concatenate them, is there a way to grep the trio in one action? Thanks. all<-c("ants","birds","cats","dogs","elks","fox"); all [1] "ants" "birds" "cats" "dogs" "elks"

Re: [R] Grep command

2016-05-04 Thread William Dunlap via R-help
No matter how expert you are at writing regular expressions, it is important to list which sorts of strings you want matched and which you do not want matched. Saying you want to match "age" but not "age2" leads to lots of possibilities. Saying how you want to categorize each string in a vector

Re: [R] Grep command

2016-05-04 Thread David Winsemius
> On May 3, 2016, at 11:16 PM, Jeff Newmiller wrote: > > Yes, but the answer is likely to depend on the actual patterns of strings in > your real data, so the sooner you go find a book or tutorial on regular > expressions the better. This is decidedly not R specific

Re: [R] Grep command

2016-05-04 Thread Doran, Harold
org> Subject: [R] Grep command Dear all In the grep command below, is there a way to identify only "age" and not "age2"? In other words, I like to greb "age" and "age2" separately, one at a time. Thanks. x<-c("abc","def","rst&q

Re: [R] Grep command

2016-05-04 Thread Niels Jespersen
> x <- c("abc","def","rst","xyz","age","age2") > grep("^age$", x) [1] 5 > grep("^age2$", x) [1] 6 > > -Oprindelig meddelelse- Fra: R-help [mailto:r-help-boun...@r-project.org] På vegne af St

Re: [R] Grep command

2016-05-04 Thread Jeff Newmiller
Yes, but the answer is likely to depend on the actual patterns of strings in your real data, so the sooner you go find a book or tutorial on regular expressions the better. This is decidedly not R specific and there are already lots of resources out there. Given the example you provide, the

Re: [R] Grep command

2016-05-04 Thread Omar André Gonzáles Díaz
Hi Steven, grep uses regex... so you can use this: -grep("age$",x): it says: match "a", then "g", then "e" and stop. The "$" menas until here and no more. > grep("age$",x) [1] 5 2016-05-04 1:02 GMT-05:00 Jim Lemon : > Hi Steven, > If this is just a one-off, you could do

Re: [R] Grep command

2016-05-04 Thread Jim Lemon
Hi Steven, If this is just a one-off, you could do this: grepl("age",x) & nchar(x)<4 returning a logical vector containing TRUE for "age" but not "age2" Jim On Wed, May 4, 2016 at 3:45 PM, Steven Yen wrote: > Dear all > In the grep command below, is there a way to identify

[R] Grep command

2016-05-03 Thread Steven Yen
Dear all In the grep command below, is there a way to identify only "age" and not "age2"? In other words, I like to greb "age" and "age2" separately, one at a time. Thanks. x<-c("abc","def","rst","xyz","age","age2") x [1] "abc" "def" "rst" "xyz" "age" "age2" grep("age2",x) [1] 6

Re: [R] grep command

2016-05-03 Thread Hervé Pagès
On 05/03/2016 06:05 AM, Jeff Newmiller wrote: Isn't that just an inefficient way to do "age" == x Yep, it's an inefficient way to do which(x == "age"). H. ? -- Hervé Pagès Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100

Re: [R] grep command

2016-05-03 Thread Jeff Newmiller
Isn't that just an inefficient way to do "age" == x ? -- Sent from my phone. Please excuse my brevity. On May 3, 2016 3:57:05 AM PDT, Ivan Calandra wrote: >What about? > >grep("^age$", x) > >Ivan > >-- >Ivan Calandra, PhD >Scientific Mediator >University of Reims

Re: [R] grep command

2016-05-03 Thread Ivan Calandra
Oh, and regarding the moderator approval, I guess it's because you're a new user to the list. Ivan -- Ivan Calandra, PhD Scientific Mediator University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89

Re: [R] grep command

2016-05-03 Thread Ivan Calandra
What about? grep("^age$", x) Ivan -- Ivan Calandra, PhD Scientific Mediator University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr -- https://www.researchgate.net/profile/Ivan_Calandra

[R] grep command

2016-05-03 Thread Steven Yen
Dear all In the grep command below, is there a way to identify only "age" and not "age2"? Thanks. > x<-c("abc","def","rst","xyz","age","age2") > x [1] "abc" "def" "rst" "xyz" "age" "age2" > grep("age2",x) [1] 6 > grep("age",x) # I need to grab "age" only, not "age2" [1] 5 6 Also, I post

Re: [R] Grep Help

2016-02-22 Thread Boris Steipe
I see numerous backticks in your code, not quotes. "`" and "'" are not the same. Backticks are not string delimiters. As for valid names: look at the help page for make.names(). HTH, Boris On Feb 22, 2016, at 1:32 PM, Burhan ul haq wrote: > Hi, > > # 1) I have read in a

[R] Grep Help

2016-02-22 Thread Burhan ul haq
Hi, # 1) I have read in a CSV file df = read.csv(file="GiftCards - v1.csv",stringsAsFactors=FALSE) head(df) str(df) # 2) converted to a tbl_df df2 = tbl_df(df) # 3) fixed the names to remove leading "X" character n = names(df2) n2 = gsub(pattern="^\\w","\\1",n) names(df2) = n2 # 4) somehow

Re: [R] grep/regexp

2015-12-01 Thread David Winsemius
> On Dec 1, 2015, at 2:47 PM, Ravi Varadhan wrote: > > Hi, > I would appreciate some help with using grep(). I have a bunch of variables > in a data frame and I would like to select some of them using grep. Here is > an example of what I am trying to do: > > vars <-

[R] grep/regexp

2015-12-01 Thread Ravi Varadhan
Hi, I would appreciate some help with using grep(). I have a bunch of variables in a data frame and I would like to select some of them using grep. Here is an example of what I am trying to do: vars <- c("Fr_I_total", "Fr_I_percent_of_CD4", "Ki.67_in_Fr_I_percent_of_Fr_I",

[R] Grep out columns using a list of strings

2015-05-08 Thread Kate Ignatius
Hi, I have a list of 150 strings, say, ap,: aajkss dfghjk sdfghk ... xxcvvn And I would l like to grep out these strings from column names in another file, af,. I've tried the following but none seem to work: aps - af[,grep(ap, colnames(af), value=TRUE)] aps - af[,grep(ap, colnames(af),

Re: [R] Grep out columns using a list of strings

2015-05-08 Thread Boris Steipe
How about %in% ? # preparing something that looks like I think your data looks like: ap - c(aajkss, dfghjk, sdfghk, xxcvvn) af - matrix(1:10, nrow=2) colnames(af) - c(aajkss, b, c, dfghjk, e) # doing what I think you need done: ap[ap %in% colnames(af)] Cheers, B. (PS. a reproducible example

[R] grep won't work finding one column

2014-10-14 Thread Kate Ignatius
I'm having an issue with grep: I have numerous columns that end with .at... when I use grep like so: df[,grep(.at,colnames(df))] it works fine. When I have one column that ends with .at, it does not work. Why is that? As this is loop with varying number of columns ending in .at I would like

Re: [R] grep won't work finding one column

2014-10-14 Thread John McKown
On Tue, Oct 14, 2014 at 9:23 AM, Kate Ignatius kate.ignat...@gmail.com wrote: I'm having an issue with grep: I have numerous columns that end with .at... when I use grep like so: df[,grep(.at,colnames(df))] it works fine. When I have one column that ends with .at, it does not work. Why

Re: [R] grep won't work finding one column

2014-10-14 Thread Kate Ignatius
For example, DF will usually have numerous columns with sample1.at sample1.dp sample1.fg sample2.at sample2.dp sample2.fg and so on I'm running this code in R as part of a shell script which runs over several different file sizes so sometimes it will come across a file with one sample in it:

Re: [R] grep won't work finding one column

2014-10-14 Thread Jeff Newmiller
Your question is missing a reproducible example, and you don't say how it does not work, so we cannot tell what is going on. Two things do come to mind, though. A) Data frame subsets with only one column by default return a vector, which is a different type of object than a single-column data

Re: [R] grep won't work finding one column

2014-10-14 Thread Ivan Calandra
Shouldn't it be grep(\\.at$,colnames(df)) with double back slash? Ivan -- Ivan Calandra University of Reims Champagne-Ardenne GEGENA² - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr https://www.researchgate.net/profile/Ivan_Calandra

Re: [R] grep won't work finding one column

2014-10-14 Thread John McKown
AT and at are not the same. If you want an case insensitive compare for the characters at you need the ignore.case=TRUE added. E.g.: df[,grep(.at,colnames(df),ignore.case=TRUE) That should match the column name you gave. Which does not match your initial description which said ending with .at.

Re: [R] grep won't work finding one column

2014-10-14 Thread John McKown
You're right. I don't use regexps in R very much. In most other languages, a single \ is needed. The R parser is different and I forgot. Thanks for the heads up. On Tue, Oct 14, 2014 at 10:01 AM, Ivan Calandra ivan.calan...@univ-reims.fr wrote: Shouldn't it be grep(\\.at$,colnames(df)) with

Re: [R] grep won't work finding one column

2014-10-14 Thread Kate Ignatius
In the sense - it does not work. it works when there are 50 samples in the file, but it does not work when there is one. The usual headings are: sample1.at sample1.dp sample1.fg sample2.at sample2.dp sample2.fg and so on to a max of sample50.at sample50.dp sample50.fg using this greps out

Re: [R] grep won't work finding one column

2014-10-14 Thread Rolf Turner
On 15/10/14 04:09, Kate Ignatius wrote: In the sense - it does not work. it works when there are 50 samples in the file, but it does not work when there is one. The usual headings are: sample1.at sample1.dp sample1.fg sample2.at sample2.dp sample2.fg and so on to a max of sample50.at

[R] grep for multiple pattern?

2014-02-13 Thread Rainer M Krug
Hi I want to search for multiple pattern as grep is doing for a single pattern, but this obviously not work: grep(an, month.name) [1] 1 grep(em, month.name) [1] 9 11 12 grep(eb, month.name) [1] 2 grep(c(an, em, eb), month.name) [1] 1 Warning message: In grep(c(an, em, eb), month.name) :

Re: [R] grep for multiple pattern?

2014-02-13 Thread PIKAL Petr
-project.org Subject: [R] grep for multiple pattern? Hi I want to search for multiple pattern as grep is doing for a single pattern, but this obviously not work: grep(an, month.name) [1] 1 grep(em, month.name) [1] 9 11 12 grep(eb, month.name) [1] 2 grep(c(an, em, eb), month.name) [1] 1

Re: [R] grep for multiple pattern?

2014-02-13 Thread Marc Schwartz
On Feb 13, 2014, at 8:43 AM, Rainer M Krug rai...@krugs.de wrote: Hi I want to search for multiple pattern as grep is doing for a single pattern, but this obviously not work: grep(an, month.name) [1] 1 grep(em, month.name) [1] 9 11 12 grep(eb, month.name) [1] 2 grep(c(an, em, eb),

Re: [R] grep for multiple pattern?

2014-02-13 Thread jim holtman
use the | in regular expressions: grep(c(an|em|eb, month.name) Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Thu, Feb 13, 2014 at 9:43 AM, Rainer M Krug rai...@krugs.de wrote: Hi I want to search

Re: [R] grep for multiple pattern?

2014-02-13 Thread Rainer M Krug
On 02/13/14, 17:23 , jim holtman wrote: use the | in regular expressions: grep(c(an|em|eb, month.name http://month.name/) Thanks - again a reason to learn regexp. Cheers, Rainer Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you

Re: [R] grep for multiple pattern?

2014-02-13 Thread Prof Brian Ripley
On 13/02/2014 16:25, Rainer M Krug wrote: On 02/13/14, 17:23 , jim holtman wrote: use the | in regular expressions: grep(c(an|em|eb, month.name http://month.name/) Thanks - again a reason to learn regexp. Note though that is an *extended* regex. They are the default in R, but not for

Re: [R] grep for multiple pattern?

2014-02-13 Thread Keith Jewell
On 13/02/2014 15:51, Marc Schwartz wrote: On Feb 13, 2014, at 8:43 AM, Rainer M Krug rai...@krugs.de wrote: Hi I want to search for multiple pattern as grep is doing for a single pattern, but this obviously not work: grep(an, month.name) [1] 1 grep(em, month.name) [1] 9 11 12 grep(eb,

Re: [R] grep(pattern = each element of a vector) ?

2013-09-12 Thread arun
-project.org Cc: Farrar, David farrar.da...@epa.gov; Green, Hyatt green.hy...@epa.gov; McManus, Michael mcmanus.mich...@epa.gov; Wahman, David wahman.da...@epa.gov Sent: Thursday, September 12, 2013 2:49 PM Subject: Re: [R] grep(pattern = each element of a vector) ? Jake, You can use the plyr

[R] grep(pattern = each element of a vector) ?

2013-09-12 Thread Beaulieu, Jake
Hi, I have a large dataframe that contains species names. I have a second dataframe that contains species names and some additional info, called 'Class', about each species. I would like match the species name is the first data frame with the 'Class' information contained in the second.

Re: [R] grep(pattern = each element of a vector) ?

2013-09-12 Thread Allen, Joel
Jake, You can use the plyr library or some form of apply. If you are on a 64bit system you can multithread and it goes much faster. something like this(for 32bit): require(plyr) df1 - data.frame(Taxa = c('blue', 'red', NA,'blue', 'red', NA,'blue', 'red', NA)) df2 - data.frame(Taxa = c( 'blue',

[R] Grep functions output

2013-08-05 Thread Lívio Cipriano
Hi, I'm writing some R scripts and I would like to grab outputs from R functions to control if tests. Example, one function outputs something like p-vale = 0.0765 and I want to program the following pseudo code in R sig = grep pvalue if (sig 0.05) a() else b() Should I use

Re: [R] Grep functions output

2013-08-05 Thread jim holtman
try this: x - p-value = 0.0765 sig - as.numeric(sub(.*=(.*), \\1, x)) sig [1] 0.0765 On Mon, Aug 5, 2013 at 10:41 AM, Lívio Cipriano lcmail4li...@gmail.comwrote: Hi, I'm writing some R scripts and I would like to grab outputs from R functions to control if tests. Example, one

Re: [R] Grep functions output

2013-08-05 Thread Jeff Newmiller
If you were to follow the recommendations in the footer of this email, you might get some better options than using grep. --- Jeff NewmillerThe . . Go Live...

Re: [R] Grep functions output

2013-08-05 Thread Lívio Cipriano
On 05 August 2013 11:11:22 Phil Spector wrote: but most functions in R that provide p-values make it possible to extract the p-value from the result of the function call without using any text Thanks for your answer. In fact it's the simple way to do it. Regards Lívio Cipriano

[R] grep help (character ommission)

2013-05-01 Thread Johannes Graumann
Hello, Banging my head against a wall here ... can anyone light the way to a pattern modification that would make the following TRUE? identical( grep( ^Intensity\\s[^HL], c(Intensity,Intensity L, Intensity H, Intensity Rep1)), as.integer(c(1,4))) Thank you for your time.

Re: [R] grep help (character ommission)

2013-05-01 Thread jim holtman
try this: identical( + grep( + ^Intensity *[HL], + c(Intensity,Intensity L, Intensity H, Intensity Rep1), + invert = TRUE), + as.integer(c(1,4))) [1] TRUE On Wed, May 1, 2013 at 4:37 AM, Johannes Graumann johannes_graum...@web.dewrote: Hello, Banging my head against a

Re: [R] grep help (character ommission)

2013-05-01 Thread Rui Barradas
Hello, The following pattern seems to do it. grep(^Intensity$|^Intensity\\s[^HL], c(Intensity,Intensity L, Intensity H, Intensity Rep1)) Hope this helps, Rui Barradas Em 01-05-2013 09:37, Johannes Graumann escreveu: Hello, Banging my head against a wall here ... can anyone light the

Re: [R] grep help (character ommission)

2013-05-01 Thread arun
: Wednesday, May 1, 2013 4:37 AM Subject: [R] grep help (character ommission) Hello, Banging my head against a wall here ... can anyone light the way to a pattern modification that would make the following TRUE? identical(   grep(     ^Intensity\\s[^HL],     c(Intensity,Intensity L, Intensity H, Intensity

Re: [R] Grep with wildcards across multiple columns

2013-03-15 Thread Bush, Daniel P. DPI
-project.org' Subject: [R] Grep with wildcards across multiple columns I have a fairly large data set with six variables set up like the following dummy: # Create fake data df - data.frame(code = c(rep(1001, 8), rep(1002, 8)), year = rep(c(rep(2011, 4), rep(2012, 4)), 2

Re: [R] Grep with wildcards across multiple columns

2013-03-15 Thread arun
To: 'r-help@r-project.org' Subject: [R] Grep with wildcards across multiple columns I have a fairly large data set with six variables set up like the following dummy: # Create fake data df - data.frame(code  = c(rep(1001, 8), rep(1002, 8)),                   year  = rep(c(rep(2011, 4), rep

[R] Grep with wildcards across multiple columns

2013-03-14 Thread Bush, Daniel P. DPI
I have a fairly large data set with six variables set up like the following dummy: # Create fake data df - data.frame(code = c(rep(1001, 8), rep(1002, 8)), year = rep(c(rep(2011, 4), rep(2012, 4)), 2), fund = rep(c(10E, 10E, 10E, 27E), 4),

Re: [R] Grep with wildcards across multiple columns

2013-03-14 Thread arun
, there is only value of obj. levels(df$obj) #[1] 100 A.K. - Original Message - From: Bush, Daniel P. DPI daniel.b...@dpi.wi.gov To: 'r-help@r-project.org' r-help@r-project.org Cc: Sent: Thursday, March 14, 2013 5:43 PM Subject: [R] Grep with wildcards across multiple columns I have

Re: [R] Grep with wildcards across multiple columns

2013-03-14 Thread William Dunlap
...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bush, Daniel P. DPI Sent: Thursday, March 14, 2013 2:43 PM To: 'r-help@r-project.org' Subject: [R] Grep with wildcards across multiple columns I have a fairly large data set with six variables set up like the following

[R] grep txt file names from html

2012-10-31 Thread chuck.01
Sorry, I know I should read a little 1st about this, but I am actually just helping somebody really quick and need help too. I want to grep all of the names of the .txt files mentioned on this html web page: http://www.epa.gov/emap/remap/html/three/data/index.html Thanks ahead of time. --

Re: [R] grep txt file names from html

2012-10-31 Thread Sarah Goslee
they're all of the form http.*txt but the best way to grep them (by which I assume you mean extract the file names from the page source) depends on what you plan to do with them, and what sort of output you expect. It isn't even clear whether you plan to do this in R. Sarah On Wed, Oct 31,

Re: [R] grep txt file names from html

2012-10-31 Thread David Winsemius
On Oct 31, 2012, at 9:56 AM, chuck.01 wrote: Sorry, I know I should read a little 1st about this, but I am actually just helping somebody really quick and need help too. I want to grep all of the names of the .txt files mentioned on this html web page:

Re: [R] grep txt file names from html

2012-10-31 Thread chuck.01
Sorry Sarah. I want to store them as a vector for use later. so, similar to this: links - c(http://www.epa.gov/emap/html/data/surfwatr/data/mastreams/9396/benthic/benmet.txt;, http://www.epa.gov/emap/html/data/surfwatr/data/mastreams/9396/location/watchr.txt;,

[R] grep and XML

2012-04-16 Thread Simon Kiss
Hi all: I struggle a lot scraping web data. I still haven't got a handle on the XML package. I'd like to get particular exchange rates from this table: https://raw.github.com/currencybot/open-exchange-rates/master/latest.json This is the code that I'm working with: library(RCurl) library(XML)

Re: [R] grep and XML

2012-04-16 Thread Henrique Dallazuanna
Try this: library(rjson) j - fromJSON(file = 'https://raw.github.com/currencybot/open-exchange-rates/master/latest.json') j$rates$USD On Mon, Apr 16, 2012 at 6:03 PM, Simon Kiss sjk...@gmail.com wrote: Hi all: I struggle a lot scraping web data. I still haven't got a handle on the XML

[R] grep TRUE/FALSE

2012-01-25 Thread Ana
Is there a way to get a TRUE/FALSE condition as result, when using grep ? c=The file will be updated if grep(updated,c)==1 then I get TRUE but How can I deal with grep(new,c) ? it gives integer(0) Thanks in advance. __ R-help@r-project.org mailing

Re: [R] grep TRUE/FALSE

2012-01-25 Thread Uwe Ligges
Yes, use grepl() rather than grep(). uwe Ligges On 25.01.2012 12:28, Ana wrote: Is there a way to get a TRUE/FALSE condition as result, when using grep ? c=The file will be updated if grep(updated,c)==1 then I get TRUE but How can I deal with grep(new,c) ? it gives integer(0) Thanks in

[R] grep fixed (?) in 2.14

2011-11-03 Thread Stephen Sefick
#This is probably due to my incomplete understanding of grep, but the below code has been working for some time to #search for .R with anything in front of it and return a list of scripts to source. Likely, the syntax for the #grep statement has been wrong all along. scripts2source -

Re: [R] grep fixed (?) in 2.14

2011-11-03 Thread Sarah Goslee
Hi, . and * both mean something different in regular expressions than in command-line wildcards. You need: grep(.*\\.R$, scripts2source) which parses to .- any character *- any number of times \\. - an actual . escaped as R requires R - the R denoting a script $ - at the end of the

Re: [R] grep fixed (?) in 2.14

2011-11-03 Thread jim holtman
your syntax is wrong, you need: scripts2source[grep(*\\.R$, scripts2source)] Notice the '\\.' to escape the special meaning of '.', and the $ to anchor to the end of the line. On Thu, Nov 3, 2011 at 8:54 AM, Stephen Sefick sas0...@auburn.edu wrote: #This is probably due to my incomplete

Re: [R] grep fixed (?) in 2.14

2011-11-03 Thread Stephen Sefick
That did the trick. I have read about regular expressions often, and sometimes I get them right and sometimes I don't. Is there a good reference resource that anyone could suggest? Thanks for all of the help. Stephen Sefick On 11/03/2011 08:03 AM, jim holtman wrote: your syntax is

[R] grep lines before or after pattern matched?

2011-07-11 Thread Simon Kiss
Dear colleagues, I have a series of newspaper articles in a text file, downloaded from a text file. They look as follows: Document 1 of 100 \n \n \n Newspaper Name \n \n Day Date I have a series of grep scripts that can extract the date and convert it to a date object, but I can't figure out

Re: [R] grep lines before or after pattern matched?

2011-07-11 Thread Joshua Wiley
Dear Simon, Maybe I don't understand properlyif you are doing this in R, can't you just pick the line you want? Josh ## print your data to clipboard cat(Document 1 of 100 \n \n \n Newspaper Name \n \n Day Date, file = clipboard) ## read data in, and only select the 4th line to pass to

Re: [R] grep lines before or after pattern matched?

2011-07-11 Thread Simon Kiss
Hi Josh, Sorry for the insufficient introduction. This might work, but I'm not sure. The file that I have includes up to 100 documents (Document 1, Document 2, Document 3Document 100) with the newspaper name following 4 lines below each Document number. I'm using readlines to get the text

Re: [R] grep lines before or after pattern matched?

2011-07-11 Thread Joshua Wiley
If you know you can find the start of the document (say that line always starts with Document...), then: grep(Document+., yourfile, value = FALSE) + 4 should give you 4 lines after each line where Document occurred. No loop needed :) On Mon, Jul 11, 2011 at 10:25 AM, Simon Kiss

Re: [R] grep lines before or after pattern matched?

2011-07-11 Thread Simon Kiss
Josh, that's amazing. Is there any way to have it grab two different lines after the grep, say the second and the fourth line? There's some other information in the text file I'd like to grab. I could do two separate commands, but I'd like to know if this could be done in one command... Simon

Re: [R] grep lines before or after pattern matched?

2011-07-11 Thread Joshua Wiley
Try this (untested as I'm on my iPhone now): index - grep(Document+., yourfile, value = FALSE) index - c(index + 2, index + 4) You just need to make sure you avoid recycling, e.g., 1:10 + c(2, 4) # not what you want If you want a sufficient number of lines that manually writing index + becomes

  1   2   >