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
Th
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 si
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
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.
gsub("","
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 wrote:
> Hi all,
>
> I realize that the backslash is an escape character in R, therefore, I
> am trying to replace it with a forwar
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
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
Wednesday, March 27, 2013 5:17 PM
> To: Shane Carey
> Cc: r-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,
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:
txt<- "LOI ."
gsub("[.]","%",txt)
#[1] "LOI %"
A.K.
From: Shane Carey
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 o
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
https://stat.ethz.c
v_Place)
Students1
# ID Name Fav_Place
#1 101 Andrew Tucson AZ
#2 201 John San Francisco
#3 303 Julie California/New York City
#4 304 Monica New York City
A.K.
- Original Message -
From: Sapana Lohani
To: R help
Cc:
Sent: Mond
ot;ID Name Fav_Place" "101 Andrew Tucson,AZ"
#[3] "201 John SanFrancisco" "303 Julie California/New York City"
#[5] "304 Monica New York City"
A.K.
- Original Message -
From: Sapana Lohani
To: R help
essage -
From: Sapana Lohani
To: R help
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"
Take a look at gsub()
Michael
On Aug 27, 2012, at 6:47 PM, Sapana Lohani 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 with Tucson & N
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]]
__
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'
, yourd
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
https://stat
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("\\+\\
You are too good :)
Thanks a lot have a nice weekend
B.R
Alex
From: jim holtman
Cc: "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+0_fi
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 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 like
>
>
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 piec
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 strin
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{
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
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 wrote:
> Hi all,
>
> I'm having a problem once again, trying to do something very simple.
> Consider
> the following data frame:
>
> x <- read.table(textConnection("
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=TRU
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", "
28 matches
Mail list logo