Skip to content
Prev 5296 / 29559 Next

Merging data frame for SpPolDF

Thanks. I might be wrong, but I think that your example is different.
The problem comes up when the second dataframe does not
have values for all cases  that are present in the first one. For example

 > a1 <-data.frame(letras=c("A","B","C","D"),nums=c("1","2","3","4"))
 > a2 <-data.frame(letras=c("A","C","D"),nums=c("10","30","40"))
 > a1
  letras nums
1      A    1
2      B    2
3      C    3
4      D    4
 > a2
  letras nums
1      A   10
2      C   30
3      D   40
 > a2 <-data.frame(letters=c("A","C","D"),cods=c("10","30","40"))
 > merge(a1,a2,by.x="letras",by.y="letters",all.x=T,sort=F)
  letras nums cods
1      A    1   10
2      C    3   30
3      D    4   40
4      B    2 <NA>

which disrupts the ordering in a1 and thus creates a risk for
puting the merged dataframe in the SpPolDF

And what you say would be:

 > a2[match(a1$letras, a2$letters), ]
   letters cods
1        A   10
NA    <NA> <NA>
2        C   30
3        D   40

which would not solve the problem.

Perhaps I did not correctly interpret your solution?

Agus
Torleif Markussen Lunde wrote:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alobolistas.vcf
Type: text/x-vcard
Size: 251 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090319/6e9d21b3/attachment.vcf>