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
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 of text as follows "LOI ."
How do I replace th
HI,
You can also try this:
Students1<-data.frame(ID=c(101,201,303,304),Name=c("Andrew","John","Julie","Monica"),Fav_Place=c("Phoenix
AZ","San Francisco","California/New York","New York"))
gsubfun<-function(pattern,replacement,x, ...){
for(i in seq_along(pattern))
x<-gsub(pattern[i],replacement
Hi,
Try this:
dat1<-readLines(textConnection(
"ID Name Fav_Place
101 Andrew Phoenix,AZ
201 John SanFrancisco
303 Julie California/New York
304 Monica New York"))
gsub("Phoenix","Tucson",gsub("New York","New York City",dat1))
#[1] "ID Name Fav_Place" "101 Andrew Tucson,AZ
Hi,
Try this:
set.seed(1)
dat1<-data.frame(A=sample(letters[20:25],replace=TRUE),B=sample(letters[1:6],replace=TRUE),C=c(letters[1:3],letters[3:1]),D=sample(letters[2:7],replace=TRUE),E=sample(letters[21:26],replace=TRUE))
newdat<-list()
for(i in 1:ncol(dat1)){
newdat[[i]]<-list()
newdat[[i]]<
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
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
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
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
22 matches
Mail list logo