Re: [R] read a table ignoring specific rows ?

From: Sean O'Riordain <sean.oriordain_at_gmail.com>
Date: Tue 23 Aug 2005 - 03:38:41 EST

Can you read in the entire file as a data.frame; and then construct a new data.frame which excludes some rows?

perhaps something along the lines of...

> fred.file <- data.frame()
> fred.file <- edit(fred.file)
> fred.file

  colA colB colC
1 1 4 2
2 2 3 3
3 3 5 4
4 4 3 3
5 5 2 25
> fred.new <- fred.file[fred.file$colC <= 3,]
> fred.new

  colA colB colC
1 1 4 2
2 2 3 3
4 4 3 3

s/

On 22/08/05, vincent@7d4.com <vincent@7d4.com> wrote:
> Dear R users,
> First of all sorry for this question, surely quite naive.
> (I searched on the R site but was unable to find by myself).
>
> I have a table, called infile :
> 1 2 3

> 4 5 6
> 7 8 9
>
> I would like to read it and ignore the rows with 1st element > 3
> I do it now with a for loop, and it's ok,
> but I was expecting something simpler, like :
>
> intable = read.table(infile);
> newtable = intable[isgoodrow(intable)];
>
> where : isgoodrow = function(therow)
> {if (therow$V1 > 3) return(F) else return(T);};
>
> (... but this don't work).
>
> So, could somebody please tell me if there is a way to read
> a table ignoring specific rows, without using a for loop ?
> ... and if yes how ?
>
> Thanks
> Vincent
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Aug 23 03:42:06 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:55 EST