Re: [R] Find and replace backslashes XXXX

2015-05-27 Thread Duncan Murdoch
On 26/05/2015 9:56 PM, Ista Zahn wrote: Escape the backslash with another backslash, i.e., gsub(\\,/,X:\\Classes\\TT\\Automation, fixed = TRUE) ... and note that if you want to use a regular expression (i.e. fixed = FALSE), you would need another level of escaping, i.e.

Re: [R] Find and replace backslashes XXXX

2015-05-27 Thread Thierry Onkelinx
Since the character looks like a Windows file path, you could use normalizePath() instead of gsub(). normalizePath(X:\\Classes\\TT\\Automation, winslash = /, mustWork = FALSE) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie

Re: [R] Find and replace backslashes XXXX

2015-05-27 Thread Duncan Murdoch
On 27/05/2015 8:55 AM, Dan Abner wrote: Hi Ista, Is there no way to not escape the backslash in the pathway? You don't need to escape it if you read it from a file, get it from list.files(), etc. You only need to escape it if you are writing a literal string in R code. Duncan Murdoch The

Re: [R] Find and replace backslashes XXXX

2015-05-27 Thread Dan Abner
Hi Ista, Is there no way to not escape the backslash in the pathway? The pathway is going to change and will become very long and I need to do this programmatically. Beside, escaping the backslash defeats the purpose of using gsub. If I could do this manually each and every time, I would change

[R] Find and replace backslashes XXXX

2015-05-26 Thread Dan Abner
Hi all, I realize that the backslash is an escape character in R, therefore, I am trying to replace it with a forward slash. Can someone please suggest how to get this code to work? lib-gsub(\,/,X:\Classes\TT\Automation) Error: unexpected symbol in lib-gsub(\,/,X Thanks, Dan

Re: [R] Find and replace backslashes XXXX

2015-05-26 Thread Ista Zahn
Escape the backslash with another backslash, i.e., gsub(\\,/,X:\\Classes\\TT\\Automation, fixed = TRUE) best, Ista On Tue, May 26, 2015 at 9:30 PM, Dan Abner dan.abne...@gmail.com wrote: Hi all, I realize that the backslash is an escape character in R, therefore, I am trying to replace it

Re: [R] find and replace missing data in several different files

2013-04-27 Thread Zilefac Elvis
Hello, I have a question and need your help urgently. I am new to R but want to learn it. I have several files in a folder which I have imported to R using : temp = list.files(pattern=*.txt) myfiles = lapply(temp, read.delim) The resulting files are on the workspace stored as List[110]. So

[R] find and replace characters in a string

2013-03-27 Thread Shane Carey
Hi, I have a string of text as follows LOI . How do I replace the dot with (%) gsub(.,(%),LOI .) gives (%)(%)(%)(%)(%) Thanks -- Shane [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] find and replace characters in a string

2013-03-27 Thread arun
txt-  LOI . gsub([.],%,txt) #[1] LOI % A.K. From: Shane Carey careys...@gmail.com To: r-help@r-project.org Sent: Wednesday, March 27, 2013 12:09 PM Subject: [R] find and replace characters in a string Hi, I have a string of text as follows LOI . How do I

Re: [R] find and replace characters in a string

2013-03-27 Thread Rui Barradas
Hello, The period is a metacharacter so you have to escape it. The period is escaped with a '\'. In it's turn, '\' is a metacharacter so it needs to be escaped. Hence the double'\\'. x - LOI . gsub(\\., (%), x) Hope this helps, Rui Barradas Em 27-03-2013 16:09, Shane Carey escreveu: Hi,

Re: [R] find and replace characters in a string

2013-03-27 Thread PIKAL Petr
-help@r-project.org Subject: Re: [R] find and replace characters in a string Hello, The period is a metacharacter so you have to escape it. The period is escaped with a '\'. In it's turn, '\' is a metacharacter so it needs to be escaped. Hence the double'\\'. x - LOI . gsub(\\., (%), x

Re: [R] find and replace

2012-08-28 Thread arun
-help@r-project.org Cc: Sent: Monday, August 27, 2012 4:19 PM Subject: [R] find and replace I have 5 (A,B,C,D,E) columns in my dataframe. I want to replace all x with y and all a with b within these 5 columns. Can I do it in one step? Thanks     [[alternative HTML version deleted

Re: [R] find and replace

2012-08-28 Thread arun
#[3] 201 John SanFrancisco  303 Julie California/New York City #[5] 304 Monica  New York City A.K. - Original Message - From: Sapana Lohani lohani.sap...@ymail.com To: R help r-help@r-project.org Cc: Sent: Monday, August 27, 2012 7:47 PM Subject: [R] find and replace Hi

Re: [R] find and replace

2012-08-28 Thread arun
City #4 304 Monica    New York City A.K. - Original Message - From: Sapana Lohani lohani.sap...@ymail.com To: R help r-help@r-project.org Cc: Sent: Monday, August 27, 2012 7:47 PM Subject: [R] find and replace Hi, My data frame (Students) is ID Name Fav_Place 101 Andrew

[R] find and replace

2012-08-27 Thread Sapana Lohani
I have 5 (A,B,C,D,E) columns in my dataframe. I want to replace all x with y and all a with b within these 5 columns. Can I do it in one step? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] find and replace

2012-08-27 Thread jim holtman
I am making the assumption that all the columns are character and not factors: for (i in c(A, B, C, D, E)){ yourdf[[i]] - ifelse(yourdf[[i]] == 'x' , 'y' , ifelse(yourdf[[i]] == 'a' , 'b' , yourdf[[i]]

[R] find and replace

2012-08-27 Thread Sapana Lohani
Hi, My data frame (Students) is ID Name Fav_Place 101 Andrew  Phoenix AZ 201 John San Francisco 303 JulieCalifornia / New York 304 Monica  New York How can I replace Phoenix with Tucson New York with New York City in the df? Thanks [[alternative HTML version deleted]]

Re: [R] find and replace

2012-08-27 Thread R. Michael Weylandt michael.weyla...@gmail.com
Take a look at gsub() Michael On Aug 27, 2012, at 6:47 PM, Sapana Lohani lohani.sap...@ymail.com wrote: Hi, My data frame (Students) is ID Name Fav_Place 101 Andrew� Phoenix AZ 201 John San Francisco 303 JulieCalifornia / New York 304 Monica� New York How can I replace Phoenix

[R] find and replace string

2011-12-02 Thread Alaios
Dear all, I would like to search in a string for the second occurrence of a symbol and replace the symbol after it For example my strings look like sta_+1+0_field2ndtry_$01.cfg I want to find the digit that comes after the second +, in that case is zero and then over a loop create the

Re: [R] find and replace string

2011-12-02 Thread jim holtman
try this: x - c('sta_+1+0_field2ndtry_$01.cfg' + , 'sta_+1+0_field2ndtry_$01.cfg' + , 'sta_+1-0_field2ndtry_$01.cfg' + , 'sta_+1+0_field2ndtry_$01.cfg' + ) # find matching fields values - grep([^+]*\\+[^+]*\\+0, x, value = TRUE) # split into two pieces

Re: [R] find and replace string

2011-12-02 Thread christiaan pauw
If the length of the fists part is constant (the sta_+1+ part) the you can use substr() On 2 December 2011 13:30, Alaios ala...@yahoo.com wrote: Dear all, I would like to search in a string for the second occurrence of a symbol and replace the symbol after it For example my strings look

Re: [R] find and replace string

2011-12-02 Thread Alaios
You are too good :) Thanks a lot have a nice weekend B.R Alex From: jim holtman jholt...@gmail.com Cc: R-help@r-project.org R-help@r-project.org Sent: Friday, December 2, 2011 1:51 PM Subject: Re: [R] find and replace string try this: x - c('sta_+1

Re: [R] find and replace string

2011-12-02 Thread Sarah Goslee
You've been given a workable solution already, but here's a one-liner: x - c('sta_+1+0_field2ndtry_$01.cfg' , 'sta_+B+0_field2ndtry_$01.cfg' , 'sta_+1+0_field2ndtry_$01.cfg' , 'sta_+9+0_field2ndtry_$01.cfg') sapply(1:length(x), function(i)gsub(\\+(.*)\\+., paste(\\+\\1\\+,

[R] Find and replace all the elements in a data frame

2011-02-17 Thread Josh B
Hi all, I'm having a problem once again, trying to do something very simple. Consider the following data frame: x - read.table(textConnection(locus1 locus2 locus3 A T C A T NA T C C A T G), header = TRUE) closeAllConnections() I am trying to make a new data frame, replacing A with A/A, T with

Re: [R] Find and replace all the elements in a data frame

2011-02-17 Thread Sarah Goslee
Josh, you've made it far too complicated. Here's one simpler way (note that I changed your read.table statement to make the values NOT factors, since I wouldn't think you want that). x - read.table(textConnection(locus1 locus2 locus3 + A T C + A T NA + T C C + A T G), header = TRUE, as.is=TRUE)

Re: [R] Find and replace all the elements in a data frame

2011-02-17 Thread Henrique Dallazuanna
Try this: xNew - as.data.frame(mapply(paste, x, x, sep = /)) xNew[is.na(x)] - NA xNew On Thu, Feb 17, 2011 at 2:54 PM, Josh B josh...@yahoo.com wrote: Hi all, I'm having a problem once again, trying to do something very simple. Consider the following data frame: x -

Re: [R] Find and replace all the elements in a data frame

2011-02-17 Thread baptiste auguie
Hi, You could use car::recode to change the levels of the factors, library(car) transform(x, locus1 = recode(locus1, 'A' = 'A/A' ; else = 'T/T'), locus2 = recode(locus2, 'T'='T/T' ; 'C' = 'C/C'), locus3 = recode(locus3, 'C'='C/C' ; 'G' = 'G/G')) HTH,

Re: [R] Find and replace all the elements in a data frame

2011-02-17 Thread Gong-Yi Liao
You may write as this: for (i in 1:nrow(x)){ for (j in 1:ncol(x)){ if (!is.na(x[i, j])) { if(x[i, j] == 'A') {x2[i, j] - 'A/A'} else{ if(x[i, j] == 'T') {x2[i, j] - 'T/T'} else{ if(x[i, j] == 'G') {x2[i, j] - 'G/G'} else{