[R-sig-Geo] merge 2 txt file

Alex Mandel tech_dev at wildintellect.com
Wed Nov 5 03:01:30 CET 2008


Alessandro wrote:
> Hi all,
> 
>  
> 
> I have two txt file with X,Y,Z column and I need to merge together
> 
>  
> 
> I tried 
> 
> file_all <- merge("file1.txt","file2.txt")
> 
> but I don't sure about the result. Is It this code correct?
> 
> Thanks Ale 
> 
> 

That would merge 2 data frames together. If you want to merge files in R
you need to import the files 1st then merge them.
Something like:

one <- read.csv("file1.txt",sep=",",header=TRUE)
two <- read.csv("file2.txt",sep=",",header=TRUE)
both <- merge(one,two)
write.table(both, file="both.txt"))

See
http://stat.ethz.ch/R-manual/R-patched/library/utils/html/read.table.html
and
http://stat.ethz.ch/R-manual/R-patched/library/utils/html/write.table.html


Alternately there are lots of other ways to do this outside of R
especially if you're on Mac or Linux, like cat.

Alex




More information about the R-sig-Geo mailing list