Skip to content

Merging data frames, or one column/vector with a data frame filling out empty rows with NA's

3 messages · Johannes G. Madsen, Gabor Grothendieck, David Winsemius

#
Try this (where SNP1x is same as SNP1 from your post
but without the last line).  If the merge below does not work
on real data set due to size then try the sqldf alternative
as it
+ structure(list(Animal = c(194073197L, 194073197L, 194073197L,
+ 194073197L, 194073197L), Marker = structure(1:5, .Label = c("P1001",
+ "P1002", "P1004", "P1005", "P1006", "P1007"), class = "factor"),
+     x = c(2L, 1L, 2L, 0L, 2L)), .Names = c("Animal", "Marker",
+ "x"), row.names = c("3213", "1295", "915", "2833", "1487"), class =
"data.frame")
+ structure(list(Animal = c(194073197L, 194073197L, 194073197L,
+ 194073197L, 194073197L, 194073197L), Marker = structure(1:6, .Label
= c("P1001",
+ "P1002", "P1004", "P1005", "P1006", "P1007"), class = "factor"),
+     Y = c(0.021088, 0.021088, 0.021088, 0.021088, 0.021088, 0.021088
+     )), .Names = c("Animal", "Marker", "Y"), class = "data.frame",
row.names = c("3213",
+ "1295", "915", "2833", "1487", "1885"))
Animal Marker  x        Y
1 194073197  P1001  2 0.021088
2 194073197  P1002  1 0.021088
3 194073197  P1004  2 0.021088
4 194073197  P1005  0 0.021088
5 194073197  P1006  2 0.021088
6 194073197  P1007 NA 0.021088
Animal Marker        Y  x
1 194073197  P1001 0.021088  2
2 194073197  P1002 0.021088  1
3 194073197  P1004 0.021088  2
4 194073197  P1005 0.021088  0
5 194073197  P1006 0.021088  2
6 194073197  P1007 0.021088 NA
Animal Marker        Y  x
1 194073197  P1001 0.021088  2
2 194073197  P1002 0.021088  1
3 194073197  P1004 0.021088  2
4 194073197  P1005 0.021088  0
5 194073197  P1006 0.021088  2
6 194073197  P1007 0.021088 NA



On Wed, Apr 22, 2009 at 5:22 AM, Johannes G. Madsen
<JGM at dansksvineproduktion.dk> wrote:
#
On Apr 22, 2009, at 5:22 AM, Johannes G. Madsen wrote:

            
So what are the results of:

str(SNP4) ; str(SNP1)    # this will tell us how large these objects  
are.

And are you sure you don't want the merge to occur by Animal as well?
The second error seems pretty obvious. You are trying to merge a  
vector that has no longer any "Marker" with a dataframe that does.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT