Displaying 20 results from an estimated 20000 matches similar to: "gsub and "\""
2012 Aug 27
4
?nchar ?strsplit
Hi, my data frame is
x<-data.frame(ID=c("abc/def","abc/def/ghi","abc","mno/pqr/st/ab"))
I want to split my column ID using "/" as the place to split. How can I do that without telling the code how many sub-columns. I could use nchar(gsub("[^/]","",x$ID)) to get how many "/" are in each row of the column, but could
2010 Feb 19
8
Weird gsub behaviour
ruby 1.8.6 (2007-09-24 patchlevel 111)
str = ''\&123''
puts "abc".gsub("b", str)
puts "abc".gsub("b", "#{str}")
puts "abc".gsub("b", str.to_s)
puts "abc".gsub("b", ''\&123'')
puts "abc".gsub("b", "\&123")
>ruby test.rb
ab123c
2012 Apr 10
7
How to remove $ (Dollar sign) from string
How do I remove a "$" character from a string sub() and gsub() with "$" or
"\$" as pattern do not work.
> sub("$","","ABC$DEF")
[1] "ABC$DEF"
> sub("\$","","ABC$DEF")
Error: '\$' is an unrecognized escape in character string starting "\$"
>
2004 Dec 02
2
regex to match word boundaries
Can someone verify whether or not this is a bug.
When I substitute all occurrence of "\\B" with "X"
R seems to correctly place an X at all non-word boundaries
(whether or not I specify perl) but "\\b" does not seem to
act on all complement positions:
> gsub("\\b", "X", "abc def") # nothing done
[1] "abc def"
>
2005 Jun 09
3
dir() and RegEx and gsub()
Dear R-Users,
I have two questions:
a)
in a directory there are 3 files:
[1] "Data.~csv" "Kopie von Data.~csv" "VorlageTradefile.csv"
The command "dir( fold, pattern = "\.csv" )" gives back *all* the 3 files
With dir( fold, pattern = "\\.csv" ) I get back only VorlageTradefile.csv.
I don't understand this behaviour,
2010 Apr 30
2
drop last character in a names'vector
Hi, i have a vector filled with names:
[1] Alvaro Adela ...
[25] Beatriz Berta ...
...
[100000] ...
I would like to drop last character in every name.
I use the next program:
for (i in 1:100000) {
? ? ? ? ? ? ? ? ? ? ? ? ? largo <- nchar(names[i]-1)
? ? ? ? ? ? ? ? ? ? ? ? ? names[i] <- substring (names[i],1,largo]
? ? ? ? ? ? ? ? ? ? ? ? ?}
Is another and faster way of do it?
Thanks,
2012 Dec 17
2
Formatting a path for unix with gsub
I have a path:
path = "/nfs/users/nfs_n/ns9/
Phenotype Analysis/Results/Run_AmplRatio_neg
BinaryAll trained without akapn+tnik.csv"
I wish to replace the spaces with "\ " so that it can be read by a system
call to unix.
Using gsub I try:
> gsub(" ","\\ ",path)
[1] "/nfs/users/nfs_n/ns9/Phenotype Analysis/Results/Run_AmplRatio_neg
BinaryAll
2011 Mar 10
1
about textConnection
I need read a table in a string with special format. I used read.csv and textConnection function.
But i am confuse about textConnection by follow code.
case A: It is OK£¡
str0 <- '{"abc",{"def","X,1&Y,2&Z,3"}}'
str1 <- strsplit(str0,'"')[[1]][6]
str2 <- gsub("&","\n", str1)
con <-
2023 Mar 08
1
Augment base::replace(x, list, value) to allow list= to be a predicate?
That's an interesting example, as it's conceptually similar to what
Pavel is proposing, but structurally different. gsubfn() is more
complicated than a simple switch in the body of the function, and
wouldn't work well as an anonymous function.
Multiple dispatch can nicely encompass both of these cases. For replace(),
library(S7)
replace <- new_generic("replace",
2011 Dec 01
2
Counting the occurences of a charater within a string
I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level.
My dataframe, x, is structured as below:
Col1
abc/def
ghi/jkl/mno
I found this code on the board but it counts all occurrences of "/" in the dataframe.
chr.pos <- which(unlist(strsplit(x,NULL))=='/')
chr.count <-
2012 Mar 07
1
gsub: replacing double backslashes with single backslash
Hello everybody,
this might be a trivial question, but I have been unable to find this using
Google. I am trying to replace double backslashes with single backslashes using
gsub. There seems to be some unexpected behaviour with regards to the
replacement string "\\". The following example uses the string C:\\ which should
be converted to C:\ .
> gsub("\\\\",
2009 May 15
4
replace "%" with "\%"
Dear all,
I'm trying to gsub() "%" with "\%" with no obvious success.
> temp1 <- c("mean", "sd", "0%", "25%", "50%", "75%", "100%")
> temp1
[1] "mean" "sd" "0%" "25%" "50%" "75%" "100%"
> gsub("%",
2007 Nov 13
3
Story problem if parenthesis used in Given, When, Then or And
VERSION: rspec rails plugin current edge version
XP/Cygwin on XP
Hi,
I hit this when trying to use parenthesis in my stories ... (that''ll teach
me!).
If a scenario looks like the following:
Story "User has story with parentheses", %{
As a user
I want parenthesis
So that ... well I just do
}, :type => RailsStory do
Scenario "the Given has parentheses" do
2004 Nov 19
3
how to get to interesting part of pattern match
Hi,
I am looking for a way to extract an "interesting" part of the match to
a regular expression. For example the pattern "[./](*.)" matches a
substring that begins with either "." or "/" followed by anything. I am
interested in this "anything" w/o the "." or "/" prefix. If say I match
the pattern against "abc/foo" I
2005 Nov 27
4
gsub syntax
Hello
I know that R's string functions are not as extensive as those of Unix but
I need to do some text handling totally within an R environment because
the target is a Windows system which will not have the corresponding shell
utilities, sed, awk etc.
Can anyone explain the following gsub phenomenon to me:
>
2008 Dec 12
7
character count
Dear list,
I have a variable that consists of typed responses. I wish to compute
a variable equal to the number of characters in the original variable.
For example:
> x <- c("convert this to 32 because it has 32 characters", "this one has 22 characters", "12 characters")
[Some magic function here]
> x
[1] 32 22 12
Any ideas?
2013 Nov 17
4
quotation marks and scan
Dear R People:
I'm sure that this is a very simple problem, but I have been wresting with
it for some time.
I have the following file that has the following one line:
CRS("+init=epsg:28992")
Fair enough. I scan it into R and get the following:
> u
[1] "CRS(\"+init=epsg:28992\")"
> gsub(pattern='\"',replacement='"',x=u)
[1]
2009 Mar 22
0
gsub('(.).(.)(.)', '\\3\\2\\1', 'gsub')
there seems to be something wrong with r's regexing. consider the
following example:
gregexpr('a*|b', 'ab')
# positions: 1 2
# lengths: 1 1
gsub('a*|b', '.', 'ab')
# ..
where the pattern matches any number of 'a's or one b, and replaces the
match with a dot, globally. the answer is correct (assuming a dfa
engine).
2009 Mar 22
0
gsub('(.).(.)(.)', '\\3\\2\\1', 'gsub') (PR#13617)
Full_Name: Wacek Kusnierczyk
Version: 2.10.0 r48181
OS: Ubuntu 8.04 Linux 32bit
Submission from: (NULL) (129.241.199.135)
there seems to be something wrong with r's regexing. consider the following
example:
gregexpr('a*|b', 'ab')
# positions: 1 2
# lengths: 1 1
gsub('a*|b', '.', 'ab')
# ..
where the pattern matches any number of
2023 Mar 07
1
Augment base::replace(x, list, value) to allow list= to be a predicate?
This could be extended to sub and gsub as well which gsubfn in the
gusbfn package already does:
library(gsubfn)
gsubfn("^..", toupper, c("abc", "xyz"))
## [1] "ABc" "XYz"
On Fri, Mar 3, 2023 at 7:22?PM Pavel Krivitsky <p.krivitsky at unsw.edu.au> wrote:
>
> Dear All,
>
> Currently, list= in base::replace(x, list, value)