[R] loop, pipe connection, output objects

Gabor Grothendieck ggrothendieck at gmail.com
Fri Oct 13 19:58:08 CEST 2006


read your data frame in all at once and then cut it on x[2] and split
the result, e.g.

split(iris, cut(iris$Sepal.Length, 4:8))

Please provide reproducible code.  Without input its not reproducible.
See last line of every message to r-help.


On 10/13/06, Marco Grazzi <marco.grazzi at sssup.it> wrote:
> Hi all,
>
> I have the following -newbye- problem.
> Inside R, I am trying to process a file and creating from it many files.
> The file is organized in different columns, the second containing a code. I want to create as output objects, which contain only entries in a certain code range, and whose name contain the code itself.
> Here is my attempt
>
> indice <- (201:399)
> for(i in indice){
>  data.i <-  read.table(pipe(paste("gawk '{if ($2 >=", i," && $2<", i+1,") print $2,$3}' < base_6_mod "  , sep='')))
>    print(paste("code ...", i, "  ... done"))
> }
>
> The problems are:
> 1- My sintax "data.i" does not work, and loop only produces a big "data.i" object. My goal, obviously was to have something like data.201, data.202, etc
> (second order problem)
> 2- I wonder if the sintax for the index ($2 >=", i," && $2<", i+1,") works
>
> Thanks for your help (hoping I manged to be enough clear),
> marco
> --
>
> Marco Grazzi
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list