I think I would replace all , with . and subsequently replace all first .
with , using ^\\.
x <- gsub(",", ".", x)
gsub("^\\.", ",", x)
It's not so elegant, but it is easier to understand than backreferences and
complex regex.
Best,
Ulrik
On Tue, 13 Feb 2018, 03:38 Boris Steipe, wrote:
> You
You can either use positive lookahead/lookbehind - but support for that is a
bit flaky. Or write a proper regex, and use
backreferences to keep what you need.
R > x <- "abc 1,1 ,1 1, x,y 2,3 "
R > gsub("(\\d),(\\d)", "\\1.\\2", x, perl = TRUE)
[1] "abc 1.1 ,1 1, x,y 2.3 "
B.
> On Feb 12, 20
> On Feb 12, 2018, at 6:22 PM, Dennis Fisher wrote:
>
> R 3.4.2
> OS X
>
> Colleagues
>
> I would appreciate some help with regular expressions.
>
> I have string that looks like:
> " ITERATION ,THETA1 ,THETA2
> ,THETA3 ,THET
Hi Dennis,
How about:
# define the two values to search for
x<-2
y<-3
# create your search string and replacement string
repstring<-paste(x,y,sep=",")
newstring<-paste(x,y,sep=".")
# this is the string that you want to change
thetastring<-"SIGMA(2,3)"
sub(repstring,newstring,thetastring)
[1] "SIG
R 3.4.2
OS X
Colleagues
I would appreciate some help with regular expressions.
I have string that looks like:
" ITERATION ,THETA1 ,THETA2
,THETA3 ,THETA4 ,THETA5
,THETA6 ,THETA7
Hi Petr and Richard;
Thanks for your responses and supports. I just faced a different problem.
I have the following R codes and work well.
p <- ggplot(a, aes(x=Phenotypes, y=Metabolites, size=abs(Beta),
colour=factor(sign(Beta +
theme(axis.text=element_text(size = 5))
p1<-p+geom_point()
p2<-
Petr, there was a thinko in your response.
tmp <- data.frame(m=factor(letters[1:4]), n=1:4)
tmp
tmp$m <- factor(tmp$m, levels=c("c","b","a","d")) ## right
tmp[order(tmp$m),]
tmp <- data.frame(m=factor(letters[1:4]), n=1:4)
levels(tmp$m) <- c("c","b","a","d") ## wrong
tmp[order(tmp$m),]
changing
Hi
After melt you can change levels of your factor variable. Again with the toy
example.
> levels(temp$variable)
[1] "y1" "y2" "y3" "y4"
> levels(temp$variable) <- levels(temp$variable)[c(2,4,1,3)]
> levels(temp$variable)
[1] "y2" "y4" "y1" "y3"
>
And you will get graphs with this new levels or
8 matches
Mail list logo