-1
> mydata
[[1]]
[[1]][[1]]
     RaceIndex         Pla.         Date     RC/Track/Course        Dist.            G    RaceClass
1 16/17 Season 16/17 Season 16/17 Season        16/17 Season 16/17 Season 16/17 Season 16/17 Season
2          158           02     06/11/16 ST / "Turf" / "C+3"         1200           GF           4R
3          102           01     16/10/16   ST / "Turf" / "C"         1000           GF           4R
4          032           05     18/09/16 ST / "Turf" / "C+3"         1000           GF            4
5 15/16 Season 15/16 Season 15/16 Season        15/16 Season 15/16 Season 15/16 Season 15/16 Season
6          754           08     01/07/16 ST / "Turf" / "A+3"         1200           GF      GRIFFIN
7          706           02     12/06/16   ST / "Turf" / "C"         1000            Y      GRIFFIN
            Dr         Rtg.      Trainer       Jockey          LBW     Win Odds      Act.Wt.
1 16/17 Season 16/17 Season 16/17 Season 16/17 Season 16/17 Season 16/17 Season 16/17 Season
2            5          058      P F Yiu  C Schofield            N          7.1          129
3            3          053      P F Yiu    J Moreira          1/2          3.2          123
4           10          053      P F Yiu       K C Ng            2           22          121
5 15/16 Season 15/16 Season 15/16 Season 15/16 Season 15/16 Season 15/16 Season 15/16 Season
6            4           --      P F Yiu    K C Leung        7-3/4          5.5          115
7            3           --      P F Yiu  C Schofield           HD           99          117
                       RunningPosition  Finish Time Final Sect.Time Declar.Horse Wt.         Gear
1                         16/17 Season 16/17 Season    16/17 Season     16/17 Season 16/17 Season
2  4<U+00A0><U+00A0>4<U+00A0><U+00A0>2      1.09.58           22.59             1130           --
3  5<U+00A0><U+00A0>3<U+00A0><U+00A0>1      0.57.15           22.98             1131           --
4  4<U+00A0><U+00A0>2<U+00A0><U+00A0>5      0.57.55           23.11             1145           H-
5                         15/16 Season 15/16 Season    15/16 Season     15/16 Season 15/16 Season
6 11<U+00A0><U+00A0>7<U+00A0><U+00A0>8      1.10.58           23.05             1106            H
7  4<U+00A0><U+00A0>4<U+00A0><U+00A0>2      0.56.61           22.34             1099           H1
  Video<U+00A0>Replay<U+00A0>
1                16/17 Season
2                            
3                            
4                            
5                15/16 Season
6                            
7                            



[[2]]
[[2]][[1]]
     RaceIndex         Pla.         Date     RC/Track/Course        Dist.            G    RaceClass
1 16/17 Season 16/17 Season 16/17 Season        16/17 Season 16/17 Season 16/17 Season 16/17 Season
2          181           09     12/11/16 ST / "Turf" / "A+3"         1400            G            4
            Dr         Rtg.      Trainer       Jockey          LBW     Win Odds      Act.Wt.
1 16/17 Season 16/17 Season 16/17 Season 16/17 Season 16/17 Season 16/17 Season 16/17 Season
2            5          052       J Size    J Moreira        3-1/2          2.4          125
                                       RunningPosition  Finish Time Final Sect.Time Declar.Horse Wt.
1                                         16/17 Season 16/17 Season    16/17 Season     16/17 Season
2 5<U+00A0><U+00A0>6<U+00A0><U+00A0>7<U+00A0><U+00A0>9      1.22.80           23.68             1058
          Gear Video<U+00A0>Replay<U+00A0>
1 16/17 Season                16/17 Season

2           --   

I have the above two list of data, by rvest html_table. I would like to combine the two list but I got the following error. Any ideas how can I combine the two lists? I would like to merge them using the first row as the header...Many thanks

> write.table(x = mydata, file = "/Users/Desktop/data.csv", quote = TRUE)
Error in data.frame(list(list(RaceIndex = c("16/17 Season", "211", "146",  : 
  arguments imply differing number of rows: 15, 7, 2
Yuen Wa Ho
  • 63
  • 6
  • Maybe take a look at [this post](http://stackoverflow.com/questions/8091303/simultaneously-merge-multiple-data-frames-in-a-list). – lmo Nov 25 '16 at 14:53

2 Answers2

0

You can use merge.

Example:

df_1 <- data.frame(Name = "John", Age = 21)
df_2 <- data.frame(Name = "Maggie", Age = 5)
lst <- list(list(df_1), list(df_2)) # You have this list
merge(lst[[1]], lst[[2]], by=c("Name", "Age"), all=TRUE)

Output:

    Name Age
1   John  21
2 Maggie   5

In your case, in by parameter you will have to specify all column names.

Carles Mitjans
  • 4,786
  • 3
  • 19
  • 38
-1

Problem solved. Best solution is to use - dplyr::bind_rows

Yuen Wa Ho
  • 63
  • 6