Displaying 20 results from an estimated 2000 matches similar to: "Regular Expressions in grep"
2012 Aug 22
1
strange behaviour when sourcing inside function
Dear R community,
I encounter a problem that is counterintuitive to my understanding of
the documentation of source and the "local" argument of that function.
With the following code, I would expect the content of "test.R" to be
evaluated inside the environment of the function "test". This, however,
does not seem to be the case as the object "a" can
2012 Aug 22
1
Plot label axis with expression
Hi all,
I need help with axis in plot.
I want to edit y axis label of my plot. My data is like:
x <- c(100,50,10,1,0.1,0.05,0.001)
plot(log(x))
axTicks(2) # Label of y axis
[1] -6 -4 -2 0 2 4
I'd like that y axis label was like: e^-6, e^-4, etc. (with text "e"
superscript -6, -4, etc.) I try to use expression(), but don't work.
plot(log(x), yaxt="n")
2012 Aug 24
1
Regular expressions: stuck again...
Hi,
I'm currently reworking a report, originating from a MS Access database, but
should be implemented in R.
Now I'm facing the task to convert a lot of queries to postgreSQL.
What I want to do is make a function which takes the MS Access query as an
argument and returns the pgSQL version.
So:
SELECT [public_tblFiche].[Fichenr], [public_tblArtnr].[Artnr] FROM
[public_tblFiche],
2012 Aug 24
1
RJSONIO/rjson maximum depth?
Hi All,
has anyone run into maximum depth of nested JSON arrays in either rjson or
RJSONIO ?
I seem to be able to get up to 10 depth levels without problem, but
crossing over to 11 either causes an error or fails to load the nodes
properly.
with RJSONIO I tried:
a = fromJSON('data/myJSON.json', depth=1000)
but I still get this error:
Error in fromJSON(content, handler, default.size,
2012 Aug 25
2
sourcecode for the balloonplot function from the gplots package
Hi,
I want to take a look at the sourcecode for balloonplot. I would appreciate it if I could get help on overcoming the following problem :
> methods(balloonplot)
[1] balloonplot.default* balloonplot.table* ?
? ?Non-visible functions are asterisked
> balloonplot.default
Error: object 'balloonplot.default' not found
>
How do I access the non-visible functions?
Thanks,
Ravi??
2012 Aug 21
2
Entering a table
I'm trying to enter a frequency table manually so that I can run a
goodness of fit test (I only have the frequencies, I don't have the
raw data).
So for example, let's say I want to re-create the HorseKicks table:
library(vcd)
data(HorseKicks)
str(HorseKicks)
'table' int [1:5(1d)] 109 65 22 3 1
- attr(*, "dimnames")=List of 1
..$ nDeaths: chr [1:5]
2012 Nov 16
1
Split data frame and create a new column
I need to split a data frame into 3 columns. The column I want to split
contains indices of lag (prefix L1 or L2 and suffix 01, 03, 04), station
name (shown in the sample data as capitalized G, P and S) and pollutant
name. Names with no ?L? prefix or 01/04 suffix are lag 0. Lag 01 is average
of lag 0 and 1, and 04 is average of 0 to 4 days. How can one do that in R?
I will ignore the other
2012 Aug 28
5
return first index for each unique value in a vector
I would like to efficiently find the first index of each unique value in a
very large vector.
For example, if I have a vector
A<-c(9,2,9,5)
I would like to return not only the unique values (2,5,9) but also their
first indices (2,4,1).
I tried using a for loop with which(A==unique(A)[i])[1] to find the first
index of each unique value but it is very slow.
What I am trying to do is easily
2012 Aug 17
3
Error: level sets of factors are different?
Why the error is coming? even though the length of outcome.new$compkey and outcome.new$armkey were exactly same.
Can anyone help?
setwd("D:/AZ")
library("RODBC")
cdb_cnct <- odbcConnectExcel("AZIF_DC_GVK_NSCLC_MSALL_287papers_02072012_141450_v1_4.xls")
outcomes <- sqlFetch(cdb_cnct, "Outcomes_info")
odbcClose(cdb_cnct)
rm(cdb_cnct)
2019 Aug 29
2
Feature request: non-dropping regmatches/strextract
Thank you! I greatly appreciate your consideration, though of course it is up to you. I think many people switch to stringr/stringi simply because functions in those packages have some consistent design choices, for example, they do not drop empty/missing matches, which facilitates array-based programming. For example, in the cases where one needs to make a new column in a data.frame (data.table,
2019 Aug 29
2
Feature request: non-dropping regmatches/strextract
Thank you, I am aware that there are packages that can accomplish this. I mentioned stringr::str_extract as a function that does not drop empty matches. I think that the behavior of regmatches(..., regexpr(...))?in base R should permit an option to prevent dropping of empty matches both for sake of consistency with the rest of the language (missing data does not yield a dropped index in other
2019 Sep 02
2
Feature request: non-dropping regmatches/strextract
I think that's a good reason for not including this in regmatches; you're right, its name is somewhat suggestive of yielding matches. Also, that sounds like a great design for strcapture with an atomic prototype.
Best,
CG
2019 Aug 15
4
Feature request: non-dropping regmatches/strextract
A very common use case for regmatches is to extract regex matches into a new column in a data.frame (or data.table, etc.) or otherwise use the extracted strings alongside the input. However, the default behavior is to drop empty matches, which results in mismatches in column length if reassignment is done without subsetting.
For consistency with other R functions and compatibility with this use
2012 Aug 20
7
relating data in two data frames
Hi,
My data.frame "A" has FID like this
FID
a
a
b
b
b
c
c
d
d
d
d
Now my second data.frame "B" has age value for a, b, c, d like
FID Age
a 5
b 7
c 9
d 3
How can search for the Age column in "B" and replace the values in "A" so that my new "A" looks like this
FID Age
a 5
a 5
b 7
b 7
b 7
2012 Aug 24
6
updating elements of a vector sequentially - is there a faster way?
I would like to know whether there is a faster way to do the below
operation (updating vec1).
My objective is to update the elements of a vector (vec1), where a
particular element i is dependent on the previous one. I need to do this on
vectors that are 1 million or longer and need to repeat that process
several hundred times. The for loop works but is slow. If there is a faster
way, please let
2019 Aug 15
1
Feature request: non-dropping regmatches/strextract
Using a non-capturing group, "(?:...)" instead of "(...)", simplifies my
example a bit
> x <- c("Groucho <groucho at marx.com>", "<chico at marx.com>", "Harpo")
> strcapture("([[:alpha:]]+)?(?: *<([[:alpha:]. ]+@[[:alpha:]. ]+)>)?", x,
proto=data.frame(Name=character(), Address=character(),
2011 Nov 08
2
match first consecutive list of capitalized words in string
Dear R-Helpers,
this is my first post ever to a mailing list, so please feel free to point out any missunderstandings on my side regarding the conventions of this mailing list.
My problem:
Assuming the following character vector is given:
names <- c("filia Maria", "vidua Joh Dirck Kleve (oo 02.02.1732)", "Bernardus Engelb Franciscus Linde j.u.Doktor referendarius
2004 Feb 06
3
a grep/regexpr problem
Hi,
I'm trying to parse lines of the form:
dan001.hin (0): fingerprint={256, 411, 426, 947, 973, 976}
What I need is the sequence of number between {}. I'm using grep as
match <- grep("{([0-9,\s]*)}",s,perl=T,value=T)
where s is a character vector.
But all I get is the whole string s. I tried using regexpr in an attempt
to get just the sequence I wanted:
match <-
2004 Mar 24
1
string problems ( grep and regepxr)
Recently working with strings and data
I have found a small problem.
Windows XP
R 1.8.1
Reading data from a "txt file" with readLine.
finding a specific line with "grep" command, all OK.
but here comes the problem...
After finding the correct line(s) i need to find a substring
inside each string.
In this case "tabs" I think it represented by "\t" in the
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",