[R] how to used regular expression while reading file

2012-03-06 Thread sagarnikam123
i have file as in txt format

@ATTRIBUTE f1996 REAL
@ATTRIBUTE f1997 REAL
@ATTRIBUTE f1998 REAL
@ATTRIBUTE f1999 REAL
@ATTRIBUTE f2000 REAL
@ATTRIBUTE class {-1,1}

@DATA
2.080750,1.099070,0.927763,1.029080,-0.130763,1.265460,-0.43
1.109460,0.786453,0.445560,-0.146323,-0.996316,0.555759,0.29
-0.676530,1.693100,1.559250,1.559980,-0.982179,-1.358510,-1.
0.534396,1.677540,1.489030,0.778605,-0.183776,-1.116850,-1.4
-1.018900,0.511080,0.755641,1.013820,0.529899,0.160440,-0.08
-1.185370,-0.514473,-0.566634,1.224720,0.619244,-0.684713,-0
1.779050,0.423947,0.820696,2.525690,0.666921,0.661346,0.4253
--

i want to parse only numbers not starting with @
like

2.080750,1.099070,0.927763,1.029080,-0.130763,1.265460,-0.43
1.109460,0.786453,0.445560,-0.146323,-0.996316,0.555759,0.29
-0.676530,1.693100,1.559250,1.559980,-0.982179,-1.358510,-1.
0.534396,1.677540,1.489030,0.778605,-0.183776,-1.116850,-1.4
-1.018900,0.511080,0.755641,1.013820,0.529899,0.160440,-0.08
-1.185370,-0.514473,-0.566634,1.224720,0.619244,-0.684713,-0
1.779050,0.423947,0.820696,2.525690,0.666921,0.661346,0.4253

 putting numbers only  in array for each line

how should i assess (read)  file


--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-used-regular-expression-while-reading-file-tp4449889p4449889.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to used regular expression while reading file

2012-03-06 Thread Sarah Goslee
You could perhaps set the comment.char argument of read.table() to @.

More generally, you can use scan() and process the lines within R.

On Tue, Mar 6, 2012 at 8:41 AM, sagarnikam123 sagarnikam...@gmail.com wrote:
 i have file as in txt format

 @ATTRIBUTE f1996 REAL
 @ATTRIBUTE f1997 REAL
 @ATTRIBUTE f1998 REAL
 @ATTRIBUTE f1999 REAL
 @ATTRIBUTE f2000 REAL
 @ATTRIBUTE class {-1,1}

 @DATA
 2.080750,1.099070,0.927763,1.029080,-0.130763,1.265460,-0.43
 1.109460,0.786453,0.445560,-0.146323,-0.996316,0.555759,0.29
 -0.676530,1.693100,1.559250,1.559980,-0.982179,-1.358510,-1.
 0.534396,1.677540,1.489030,0.778605,-0.183776,-1.116850,-1.4
 -1.018900,0.511080,0.755641,1.013820,0.529899,0.160440,-0.08
 -1.185370,-0.514473,-0.566634,1.224720,0.619244,-0.684713,-0
 1.779050,0.423947,0.820696,2.525690,0.666921,0.661346,0.4253
 --

 i want to parse only numbers not starting with @
 like

 2.080750,1.099070,0.927763,1.029080,-0.130763,1.265460,-0.43
 1.109460,0.786453,0.445560,-0.146323,-0.996316,0.555759,0.29
 -0.676530,1.693100,1.559250,1.559980,-0.982179,-1.358510,-1.
 0.534396,1.677540,1.489030,0.778605,-0.183776,-1.116850,-1.4
 -1.018900,0.511080,0.755641,1.013820,0.529899,0.160440,-0.08
 -1.185370,-0.514473,-0.566634,1.224720,0.619244,-0.684713,-0
 1.779050,0.423947,0.820696,2.525690,0.666921,0.661346,0.4253

  putting numbers only  in array for each line

 how should i assess (read)  file



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How '.' is used?

2009-08-10 Thread Michael Dewey

At 17:06 09/08/2009, Peng Yu wrote:

Hi,

I know '.' is not a separator in R as in C++. I am wondering where it
discusses the detailed usage of '.' in R. Can somebody point me a
webpage, a manual or a book that discuss this?


It has a special meaning in a formula.
?formula tells you more



Regards,
Peng


Michael Dewey
http://www.aghmed.fsnet.co.uk

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How '.' is used?

2009-08-09 Thread Peng Yu
Hi,

I know '.' is not a separator in R as in C++. I am wondering where it
discusses the detailed usage of '.' in R. Can somebody point me a
webpage, a manual or a book that discuss this?

Regards,
Peng

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How '.' is used?

2009-08-09 Thread Ted Harding
On 09-Aug-09 16:06:52, Peng Yu wrote:
 Hi,
 I know '.' is not a separator in R as in C++. I am wondering where it
 discusses the detailed usage of '.' in R. Can somebody point me a
 webpage, a manual or a book that discuss this?
 
 Regards,
 Peng

To the best of my knowledge, apart from its specific use as a separator
between the integer and fractional parts of a number, . has no specific
use in R, and you can, for instance, use it just as you would use an
alphanumeric character in a name.

For instance, you could do

  . - 1.2345
  .
  # [1] 1.2345

  . - function(x) x^2
  .(12)
  # [1] 144

So, unless there is something I don't know about, there is hardly
anything to discuss about the detailed usage of '.' in R!

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 09-Aug-09   Time: 17:32:54
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How '.' is used?

2009-08-09 Thread Douglas Bates
On Sun, Aug 9, 2009 at 11:32 AM, Ted
Hardingted.hard...@manchester.ac.uk wrote:
 On 09-Aug-09 16:06:52, Peng Yu wrote:
 Hi,
 I know '.' is not a separator in R as in C++. I am wondering where it
 discusses the detailed usage of '.' in R. Can somebody point me a
 webpage, a manual or a book that discuss this?

 Regards,
 Peng

 To the best of my knowledge, apart from its specific use as a separator
 between the integer and fractional parts of a number, . has no specific
 use in R, and you can, for instance, use it just as you would use an
 alphanumeric character in a name.

 For instance, you could do

  . - 1.2345
  .
  # [1] 1.2345

  . - function(x) x^2
  .(12)
  # [1] 144

 So, unless there is something I don't know about, there is hardly
 anything to discuss about the detailed usage of '.' in R!

The ',' character is one of the characters allowed in names, hence it
can be used as you have suggested.  There are (at least) two special
usages of the '.' in names.  Following the time-honoured Unix
convention, names that begin with '.' are considered hidden names
and not listed by ls() or objects() unless you set all.names = TRUE in
the call.  Because of this convention it is inadvisable to use names
starting with '.' except when you wish to avoid potential name
conflicts.  The second special use of '.' in a name is in the
construction of the names of S3 method functions.  The method for
generic function foo applied to class bar is named foo.bar.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How '.' is used?

2009-08-09 Thread Ted Harding
On 09-Aug-09 16:53:32, Douglas Bates wrote:
 On Sun, Aug 9, 2009 at 11:32 AM, Ted
 Hardingted.hard...@manchester.ac.uk wrote:
 On 09-Aug-09 16:06:52, Peng Yu wrote:
 Hi,
 I know '.' is not a separator in R as in C++. I am wondering where it
 discusses the detailed usage of '.' in R. Can somebody point me a
 webpage, a manual or a book that discuss this?

 Regards,
 Peng

 To the best of my knowledge, apart from its specific use as a
 separator
 between the integer and fractional parts of a number, . has no
 specific
 use in R, and you can, for instance, use it just as you would use an
 alphanumeric character in a name.

 For instance, you could do

 _. - 1.2345
 _.
 _# [1] 1.2345

 _. - function(x) x^2
 _.(12)
 _# [1] 144

 So, unless there is something I don't know about, there is hardly
 anything to discuss about the detailed usage of '.' in R!
 
 The ',' character is one of the characters allowed in names, hence it
 can be used as you have suggested.  There are (at least) two special
 usages of the '.' in names.  Following the time-honoured Unix
 convention, names that begin with '.' are considered hidden names
 and not listed by ls() or objects() unless you set all.names = TRUE in
 the call.  Because of this convention it is inadvisable to use names
 starting with '.' except when you wish to avoid potential name
 conflicts.  The second special use of '.' in a name is in the
 construction of the names of S3 method functions.  The method for
 generic function foo applied to class bar is named foo.bar.

As in summary.glm, I suppose! However, this prompts a question.
In the first place, the construction of summary.glm from summary
and glm is, in the first instance, simply using . in its basic
role as a permissible character in a name. Correct?

Next -- and this is the real question -- how does R parse the name
summary.glm? In my naivety, I simply suppose that it looks for
an available function whose name is summary.glm in just the
same way as it looks for stopifnot, or for that matter data.matrix
which is not (as far as I know) a compound of a generic function
data applied to a class matrix. Then . would not have a special
(parseable) role in the name -- it is simply another letter.

But when you do have such a function, like summary.glm, does R
in fact parse it as summary then glm (i.e. look out for the
generic function summary and then specialise it to handle glm).

As I say, I suppose not. And, if not, then the special use of
the character . is simply a programmer's convention for the
construction of the name, and once the name exists the . does
not have a special (parseable) significance for R.

Just seeking clarification ... !
Thanks,
Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 09-Aug-09   Time: 19:58:32
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How '.' is used?

2009-08-09 Thread Duncan Murdoch

(Ted Harding) wrote:

On 09-Aug-09 16:53:32, Douglas Bates wrote:
  

On Sun, Aug 9, 2009 at 11:32 AM, Ted
Hardingted.hard...@manchester.ac.uk wrote:


On 09-Aug-09 16:06:52, Peng Yu wrote:
  

Hi,
I know '.' is not a separator in R as in C++. I am wondering where it
discusses the detailed usage of '.' in R. Can somebody point me a
webpage, a manual or a book that discuss this?

Regards,
Peng


To the best of my knowledge, apart from its specific use as a
separator
between the integer and fractional parts of a number, . has no
specific
use in R, and you can, for instance, use it just as you would use an
alphanumeric character in a name.

For instance, you could do

_. - 1.2345
_.
_# [1] 1.2345

_. - function(x) x^2
_.(12)
_# [1] 144

So, unless there is something I don't know about, there is hardly
anything to discuss about the detailed usage of '.' in R!
  

The ',' character is one of the characters allowed in names, hence it
can be used as you have suggested.  There are (at least) two special
usages of the '.' in names.  Following the time-honoured Unix
convention, names that begin with '.' are considered hidden names
and not listed by ls() or objects() unless you set all.names = TRUE in
the call.  Because of this convention it is inadvisable to use names
starting with '.' except when you wish to avoid potential name
conflicts.  The second special use of '.' in a name is in the
construction of the names of S3 method functions.  The method for
generic function foo applied to class bar is named foo.bar.



As in summary.glm, I suppose! However, this prompts a question.
In the first place, the construction of summary.glm from summary
and glm is, in the first instance, simply using . in its basic
role as a permissible character in a name. Correct?
  


Correct.

Next -- and this is the real question -- how does R parse the name
summary.glm? In my naivety, I simply suppose that it looks for
an available function whose name is summary.glm in just the
same way as it looks for stopifnot, or for that matter data.matrix
which is not (as far as I know) a compound of a generic function
data applied to a class matrix. Then . would not have a special
(parseable) role in the name -- it is simply another letter.
  


It doesn't do anything special when parsing.  The special sauce comes 
when the generic summary() function executes UseMethod(summary).  At 
that point, we know the class of the object, and we know the name of the 
generic, so it goes looking for a summary.glm method.


There are some subtleties to how it does that lookup (see the discussion 
in Writing R Extensions about NAMESPACES), but if you had a generic 
function calling UseMethod(data) and it was passed an object of class 
matrix, data.matrix() would be called, even though that doesn't make 
sense.  This is a flaw in the S3 system, and one of the motivations for 
the development of the S4 system.


Duncan Murdoch

But when you do have such a function, like summary.glm, does R
in fact parse it as summary then glm (i.e. look out for the
generic function summary and then specialise it to handle glm).

As I say, I suppose not. And, if not, then the special use of
the character . is simply a programmer's convention for the
construction of the name, and once the name exists the . does
not have a special (parseable) significance for R.

Just seeking clarification ... !
Thanks,
Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 09-Aug-09   Time: 19:58:32
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How '.' is used?

2009-08-09 Thread Ted Harding
On 09-Aug-09 19:31:47, Duncan Murdoch wrote:
 (Ted Harding) wrote:
 [...]
 Next -- and this is the real question -- how does R parse the name
 summary.glm? In my naivety, I simply suppose that it looks for
 an available function whose name is summary.glm in just the
 same way as it looks for stopifnot, or for that matter data.matrix
 which is not (as far as I know) a compound of a generic function
 data applied to a class matrix. Then . would not have a special
 (parseable) role in the name -- it is simply another letter.
   
 
 It doesn't do anything special when parsing.  The special sauce comes 
 when the generic summary() function executes UseMethod(summary).
 At that point, we know the class of the object, and we know the name
 of the generic, so it goes looking for a summary.glm method.
 
 There are some subtleties to how it does that lookup (see the
 discussion in Writing R Extensions about NAMESPACES), but if you had
 a generic function calling UseMethod(data) and it was passed an
 object of class matrix, data.matrix() would be called, even though
 that doesn't make sense.  This is a flaw in the S3 system, and one of
 the motivations for the development of the S4 system.

Many thanks, Duncan. I think that makes it clear! You've prompted
me to read ?UseMethod':

  When a function calling 'UseMethod(fun)' is applied to an object
  with class attribute 'c(first, second)', the system searches
  for a function called 'fun.first' and, if it finds it, applies it
  to the object.  If no such function is found a function called
  'fun.second' is tried.  If no class name produces a suitable
  function, the function 'fun.default' is used, if it exists, or an
  error results.

which is pretty explicit that the role of the . is simply to
construct a name for the system to look for.

One learns ... Thanks.
Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 09-Aug-09   Time: 21:22:23
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.