[R] Get File Names in Folder, Read Files, Update, and Write

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Sep 15 11:00:01 CEST 2010



On 15.09.2010 10:55, Suphajak Ngamlak wrote:
> Dear All,
>
>
>
> Could you please recommend how I can do this?
>
>
>
> I have several text files in one folder. Let's name them A0801.RSK,
> A0802.RSK, ....
>
> I would like R to
>
> 1)      Know all file names in this folder


?list.files


> 2)      Update value in one column of these files
> 3)      Write results in another text file with _xval in the file names


?paste

Uwe Ligges



>
>
> Below is R code for read, update, and write one file
>
>
>
> Import<-"C:/A0810.RSK"
>
> Table<-read.table(file= Import, sep = ",", head=TRUE, na.strings = "NA")
>
> Table$VALUE<-0
>
> Export<-"C:/A_XVal0810.RSK"
>
> write.table(Table, file= Export, sep = ",", col.names = TRUE)
>
>
>
> Thank you
>
> Best Regards,
>
> Suphajak Ngamlak
> Equity and Derivatives Trading
> Phatra Securities Public Company Limited
> Tel: +662-305-9179
> Email: suphajak at phatrasecurities.com
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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