[R-sig-Geo] R: merge 2 txt file (PROBLEM OF MEMORY)

Alessandro alessandro.montaghi at unifi.it
Fri Nov 7 21:03:00 CET 2008


Hi I 

The problem is this: when i merge ground1 and ground2 in one txt file
(ground) I lost many rows

EX: file ground1.txt, ground2.txt
Format file: X,Y,Z with header row and sep="," 

******************************

> ground1 <- read.delim("ground_Filtered_268000_4149000.txt",
sep=",",header=TRUE)
> ground2 <- read.delim("ground_Filtered_269000_4149000.txt",
sep=",",header=TRUE)
> summary(ground1)
       X                Y                 Z       
 Min.   :267980   Min.   :4148980   Min.   :1399  
 1st Qu.:268256   1st Qu.:4149238   1st Qu.:1505  
 Median :268528   Median :4149490   Median :1587  
 Mean   :268515   Mean   :4149491   Mean   :1595  
 3rd Qu.:268777   3rd Qu.:4149743   3rd Qu.:1683  
 Max.   :269020   Max.   :4150020   Max.   :1823  
> summary(ground2)
       X                Y                 Z       
 Min.   :268980   Min.   :4148980   Min.   :1628  
 1st Qu.:269265   1st Qu.:4149268   1st Qu.:1720  
 Median :269512   Median :4149543   Median :1753  
 Mean   :269509   Mean   :4149521   Mean   :1753  
 3rd Qu.:269753   3rd Qu.:4149768   3rd Qu.:1788  
 Max.   :270020   Max.   :4150020   Max.   :1903  
> str(ground1)
'data.frame':   2356617 obs. of  3 variables:
 $ X: num  268000 268000 268001 268002 268002 ...
 $ Y: num  4149984 4149982 4149983 4149983 4149983 ...
 $ Z: num  1543 1543 1543 1543 1543 ...
> str(ground2)
'data.frame':   3235340 obs. of  3 variables:
 $ X: num  270000 269999 269999 270000 270000 ...
 $ Y: num  4149873 4149873 4149873 4149874 4149876 ...
 $ Z: num  1744 1745 1744 1744 1744 ...
> ground <- merge(ground1,ground2)
> str(ground)
'data.frame':   89819 obs. of  3 variables:
 $ X: num  268980 268980 268980 268980 268980 ...
 $ Y: num  4148981 4149013 4149090 4149097 4149110 ...
 $ Z: num  1628 1640 1668 1670 1673 ...
>

THE result is: ground1 (=2356617) ground2 (=3235340) But the ground is only
89819

I think there is a problem of memory

Ale





-----Messaggio originale-----
Da: Ashton Shortridge [mailto:ashton at msu.edu] 
Inviato: mercoledì 5 novembre 2008 10.15
A: r-sig-geo at stat.math.ethz.ch; Alessandro
Oggetto: Re: [R-sig-Geo] merge 2 txt file

Hi Ale,

When you say merge, do you mean you want to append one onto the other, or
you 
really want to merge elements that have common x and y values?

If it's the first case, then I'd probably read both in with read.table() and

then rbind them:
dat1 <- read.table("file1.txt")
dat2 <- read.table("file2.txt")
dat3 <- rbind(dat1,dat2)

If it's the second, I can't help much. Did you try it? Did that work? If you

can't tell (if, say, the text files are really big) then make two small test

files and try that.

Ashton

On Tuesday 04 November 2008 06:52:20 pm 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
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



-- 
Ashton Shortridge
Associate Professor			ashton at msu.edu
Dept of Geography			http://www.msu.edu/~ashton
235 Geography Building		ph (517) 432-3561
Michigan State University		fx (517) 432-1671




More information about the R-sig-Geo mailing list