[R] Batch files process and String parsing

Nikhil Kaza nikhil.list at gmail.com
Wed Jul 7 21:21:27 CEST 2010


?list.files
In particular look at pattern argument.

?file.rename
?lapply
?read.table
?"["


Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina

nikhil.list at gmail.com

On Jul 7, 2010, at 1:11 PM, jd6688 wrote:

>
> Here are what i am going to accomplish:
>
> I have 400 files named as xxx.txt. the content of the file looks  
> like the
> following:
>
>    name    count
>
> 1. aaa     100
> 2. bbb    2000
> 3. ccc    300
> 4. ddd   3000
>
> ........
> more that 1000 rows in each files.
>
> these are the areas i need help:
> 1. how can i only read in the files with the string patterns ggg or  
> fff as
> part of the file names?
>  for instance, I only need the file names with the ggg or fff in it
>     xxxxx_ggg_yyyyy_1.txt
>     yyyy_fff_yyyy_xxx.txt
>
>    i don't need to read in the files, such as xxxx_aaa_yyyy.txt
>
> 2.how cam rename the files:
>
>  for instance: xxxxx_ggg_yyyyy_1.txt======>changed to ggg1a.txt
>
>
> 3.after the files read in, how can i only keep the rows with the aaa  
> and
> bbb, everything elses show be removed from the files, but the files  
> still
> remain the same file name?
>
>   for instance, in the xxxxx_ggg_yyyyy_1.txt file, it shouls looks  
> like:
> name    count
>
> 1. aaa    100
> 2. bbb    2000
> 3. aaa    300
> 4. bbb    400
>
>
> Thanks so lot, I am very new to R, I am looking forward to any helps  
> from
> you.
>
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Batch-files-process-and-String-parsing-tp2281208p2281208.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list