[R] select .txt from .txt in a directory

Simon Zehnder szehnder at uni-bonn.de
Fri Nov 8 19:59:59 CET 2013


Elvis,

first, keep things on the list - so others can learn and comment. Second, as Sarah already commented: We do not like to open unsolicited binary attachments on the list. Sarah gives a good hint how to post data to the list.

What I would do so far is use the matching columns to get the names you need from BTemperature: 

temp_inv <- read.table("Temperature Inventory", … ) (here I would change the .xlsx to a .csv and use read.csv instead of read.table)
btemp <- read.table(“BTemperature_Stations.txt”, … ) (again think about converting via Excel to .csv - it makes things far more easy) 

Check ?read.table for options - you gonna need them.

Then match
mynames <- btemp[(temp_inv[,3] %in% btemp[, 3]), 2]

Now you have the names of the stations and if your .txt files are named by the stations you can do something like:

for (name in mynames) {
tmp.table <- read.table(paste(“path/to/your/Homog_daily_min_temp/“, name, “.txt”, sep = “”), … )
…. do things with the data
}



Best

Simon
 
On 08 Nov 2013, at 19:26, Zilefac Elvis <zilefacelvis at yahoo.com> wrote:

> Hi Simon,
> Attached are my data files.
> Btemperature_Stations is my main file.
> Temperature inventory is my 'wanted' file and is a subset of Btemperature_Stations.
> Using column 3 in both files, select the files in Temperature inventory from Btemperature_Stations.
> The .zip file contains the .txt files which you will extract to a folder and do the selection in R.
> 
> Thanks,
> Atem.
>  
> 
> 
> 
> 
> On Friday, November 8, 2013 11:54 AM, Simon Zehnder <szehnder at uni-bonn.de> wrote:
> If you want to type in the names by hand, you can simply use read.table to load them into R … I still don’t get the aim of your text file handling
> 
> 
> On 08 Nov 2013, at 18:51, Zilefac Elvis <zilefacelvis at yahoo.com> wrote:
> 
> > All files are text files. They are found in a folder on my computer. 
> > Assume that I know the names of some of the files I want to select from the 300 txt files.
> > How can I do this in R.
> > Atem.
> > 
> > 
> > On Friday, November 8, 2013 11:44 AM, Simon Zehnder <szehnder at uni-bonn.de> wrote:
> > I do not understand the question. If you already know the names what is the problem to select the files by names? 
> > 
> > If you have the names but not inside of R you have to find a name pattern to avoid typing them in. Is there a pattern, e.g. da.txt, db.txt, dc.txt? 
> > 
> > 
> > On 08 Nov 2013, at 18:33, Zilefac Elvis <zilefacelvis at yahoo.com> wrote:
> > 
> > > Hi,
> > > I have 300 .txt files in a directory. Out of this 300, I need just 100 of the files.
> > > I have the names of the 100 .txt files which are also found in the 300 .txt files.
> > > How can I extract only the 100 .txt files from the 300 ,txt files?
> > > 
> > > e.g given d1.txt, ds.txt, dx.txt, df.txt...d300.txt, how can I select only d1.txt and df.txt? Remember, I have 300 of such and want to extract 100 of them with names known.
> > > 
> > > Thanks for your great help.
> > > Atem.
> > 
> > >    [[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.
> > 
> > 
> > 
> 
> 
> <BTemperature_Stations.txt><Tempearture inventory.xlsx><Homog_daily_min_temp.zip>



More information about the R-help mailing list