another useful trick that could come in handy, thanks!
baptiste
2009/11/18 Gabor Grothendieck :
> Here is a slight variation:
>
>> read.table(textConnection(grep("", input, value = TRUE)),
> + colClasses = c("NULL", "NULL", "numeric"))
> V3 V6
> 1 0.00137700 3.4644e-07
> 2 0.0
Here is a slight variation:
> read.table(textConnection(grep("", input, value = TRUE)),
+colClasses = c("NULL", "NULL", "numeric"))
V3 V6
1 0.00137700 3.4644e-07
2 0.00019412 4.8840e-08
3 0.00137700 3.4644e-07
4 0.00019412 4.8840e-08
On Wed, Nov 18, 2009 at 1:54 PM, baptis
It only works if "some text" at the beginning has no digits, dots, E
characters or sign characters.
On Wed, Nov 18, 2009 at 12:44 PM, Bert Gunter wrote:
> The previous elegant solutions required the use of the gsubfn package.
> Nothing wrong with that, of course, but I'm always curious whether st
Hi,
Thanks for the alternative approach. However, I should have made my
example more complete in that other lines may also have numeric
values, which I'm not interested in. Below is an updated problem, with
my current solution,
tc <- textConnection(
"some text
=1.3770E-03 =3.4644E-
The previous elegant solutions required the use of the gsubfn package.
Nothing wrong with that, of course, but I'm always curious whether still
relatively simple base R solutions can be found, as they are often (but not
always!) much faster. And anyway, it seems to be in the spirit of your query
to
Thanks. This is now fixed in the development version so that it gives
an error rather than crashing:
> library(gsubfn)
Loading required package: proto
Loading required package: tcltk
Loading Tcl/Tk interface ... done
> source("http://gsubfn.googlecode.com/svn/trunk/R/gsubfn.R";)
> strapply("test",
Thanks a lot, both of you.
Incidentally, I made R crash when I forgot the X argument to strapply,
library(gsubfn)
Loading required package: tcltk
Loading Tcl/Tk interface ... done
strapply("test", as.numeric)
*** caught bus error ***
address 0x13c, cause 'non-existent physical address'
Traceba
A minor variant might be the following:
library(gsubfn)
strapply(input, "\\d+\\.\\d+E[-+]?\\d+", as.numeric, simplify = rbind)
where:
- as.numeric is used in place of c in which case we do not need combine
- \\d+ matches one or more digits
- \\. matches a decimal point
- [-+]? matches -, +
Try this:
strapply(input, "([0-9]+\\.[0-9]+E-[0-9]+)", c, simplify = rbind,
combine = as.numeric)
On Wed, Nov 18, 2009 at 9:57 AM, baptiste auguie
wrote:
> Dear list,
>
> I'm seeking advice to extract some numeric values from a log file
> created by an external program. Consider the following ex
9 matches
Mail list logo