I have several arrays that I want to merge by row, but some of the column names are not the same for all the arrays. Of course, rbind did not work. What do I try next?
D
Can you provide a reproducible example? It will make it easier for us to figure out what you are doing and make it more likely that you'll get an answer.
x <- get_game_pks_mlb(as.Date("2021-08-10"), level_ids=c(1))
y <- get_game_pks_mlb(as.Date("2021-08-11"), level_ids=c(1))
xy <- rbind(x,y)
Error in match.names(clabs, names(xi)) :
names do not match previous names
I use the baseballr package to get x and y.
Can you just provide the output of dput(head(y))
and the same for x
?
dput(head(x))
structure(list(game_pk = c(632997L, 633000L, 632208L, 632940L,
632960L, 632948L), link = c("/api/v1.1/game/632997/feed/live",
"/api/v1.1/game/633000/feed/live", "/api/v1.1/game/632208/feed/live",
"/api/v1.1/game/632940/feed/live", "/api/v1.1/game/632960/feed/live",
"/api/v1.1/game/632948/feed/live"), gameType = c("R", "R", "R",
"R", "R", "R"), season = c("2021", "2021", "2021", "2021", "2021",
"2021"), gameDate = c("2021-08-10T18:20:00Z", "2021-08-11T00:05:00Z",
"2021-08-10T22:07:00Z", "2021-08-11T02:07:00Z", "2021-08-10T23:05:00Z",
"2021-08-10T23:05:00Z"), officialDate = c("2021-08-10", "2021-08-10",
"2021-08-10", "2021-08-10", "2021-08-10", "2021-08-10"), rescheduledFrom = c("2021-08-10T00:05:00Z",
NA, "2021-04-11T17:07:00Z", NA, NA, NA), rescheduledFromDate = c("2021-08-09",
NA, "2021-04-11", NA, NA, NA), isTie = c(FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE), gameNumber = c(1L, 2L, 1L, 2L, 1L, 1L),
publicFacing = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), doubleHeader = c("S",
"S", "S", "S", "N", "N"), gamedayType = c("P", "P", "P",
"P", "P", "P"), tiebreaker = c("N", "N", "N", "N", "N", "N"
), calendarEventID = c("14-632997-2021-08-10", "14-633000-2021-08-10",
"14-632208-2021-08-10", "14-632940-2021-08-10", "14-632960-2021-08-10",
"14-632948-2021-08-10"), seasonDisplay = c("2021", "2021",
"2021", "2021", "2021", "2021"), dayNight = c("day", "night",
"day", "night", "night", "night"), description = c("Makeup of 8/9ppd",
NA, "in Anaheim, CA; Makeup of 4/11 PPD", NA, NA, NA), scheduledInnings = c(7L,
7L, 7L, 7L, 9L, 9L), reverseHomeAwayStatus = c(FALSE, FALSE,
TRUE, FALSE, FALSE, FALSE), inningBreakLength = c(120L, 120L,
120L, 120L, 120L, 120L), gamesInSeries = c(4L, 4L, 4L, 4L,
3L, 3L), seriesGameNumber = c(1L, 2L, 1L, 2L, 1L, 1L), seriesDescription = c("Regular Season",
"Regular Season", "Regular Season", "Regular Season", "Regular Season",
"Regular Season"), recordSource = c("S", "S", "S", "S", "S",
"S"), ifNecessary = c("N", "N", "N", "N", "N", "N"), ifNecessaryDescription = c("Normal Game",
"Normal Game", "Normal Game", "Normal Game", "Normal Game",
"Normal Game"), resumeDate = c(NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_
), resumeGameDate = c(NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_), status.abstractGameState = c("Final",
"Final", "Final", "Final", "Final", "Final"), status.codedGameState = c("F",
"F", "F", "F", "F", "F"), status.detailedState = c("Final",
"Final", "Final", "Final", "Final", "Final"), status.statusCode = c("F",
"F", "F", "F", "F", "F"), status.startTimeTBD = c(FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE), status.abstractGameCode = c("F",
"F", "F", "F", "F", "F"), teams.away.score = c(4L, 6L, 6L,
4L, 9L, 4L), teams.away.isWinner = c(TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE), teams.away.splitSquad = c(FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE), teams.away.seriesNumber = c(36L, 36L,
37L, 37L, 36L, 37L), teams.away.leagueRecord.wins = c(67L,
68L, 57L, 61L, 55L, 56L), teams.away.leagueRecord.losses = c(46L,
46L, 56L, 51L, 60L, 56L), teams.away.leagueRecord.pct = c(".593",
".596", ".504", ".545", ".478", ".500"), teams.away.team.id = c(158L,
158L, 108L, 141L, 116L, 138L), teams.away.team.name = c("Milwaukee Brewers",
"Milwaukee Brewers", "Los Angeles Angels", "Toronto Blue Jays",
"Detroit Tigers", "St. Louis Cardinals"), teams.away.team.link = c("/api/v1/teams/158",
"/api/v1/teams/158", "/api/v1/teams/108", "/api/v1/teams/141",
"/api/v1/teams/116", "/api/v1/teams/138"), teams.home.score = c(2L,
3L, 3L, 0L, 4L, 1L), teams.home.isWinner = c(FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE), teams.home.splitSquad = c(FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE), teams.home.seriesNumber = c(37L,
37L, 37L, 37L, 37L, 36L), teams.home.leagueRecord.wins = c(52L,
52L, 60L, 57L, 38L, 41L), teams.home.leagueRecord.losses = c(62L,
63L, 51L, 57L, 73L, 72L), teams.home.leagueRecord.pct = c(".456",
".452", ".541", ".500", ".342", ".363"), teams.home.team.id = c(112L,
112L, 141L, 108L, 110L, 134L), teams.home.team.name = c("Chicago Cubs",
"Chicago Cubs", "Toronto Blue Jays", "Los Angeles Angels",
"Baltimore Orioles", "Pittsburgh Pirates"), teams.home.team.link = c("/api/v1/teams/112",
"/api/v1/teams/112", "/api/v1/teams/141", "/api/v1/teams/108",
"/api/v1/teams/110", "/api/v1/teams/134"), venue.id = c(17L,
17L, 1L, 1L, 2L, 31L), venue.name = c("Wrigley Field", "Wrigley Field",
"Angel Stadium", "Angel Stadium", "Oriole Park at Camden Yards",
"PNC Park"), venue.link = c("/api/v1/venues/17", "/api/v1/venues/17",
"/api/v1/venues/1", "/api/v1/venues/1", "/api/v1/venues/2",
"/api/v1/venues/31"), content.link = c("/api/v1/game/632997/content",
"/api/v1/game/633000/content", "/api/v1/game/632208/content",
"/api/v1/game/632940/content", "/api/v1/game/632960/content",
"/api/v1/game/632948/content")), row.names = c(NA, 6L), class = "data.frame")
dput(head(y))
structure(list(game_pk = c(632927L, 632904L, 632935L, 632966L,
632959L, 632922L), link = c("/api/v1.1/game/632927/feed/live",
"/api/v1.1/game/632904/feed/live", "/api/v1.1/game/632935/feed/live",
"/api/v1.1/game/632966/feed/live", "/api/v1.1/game/632959/feed/live",
"/api/v1.1/game/632922/feed/live"), gameType = c("R", "R", "R",
"R", "R", "R"), season = c("2021", "2021", "2021", "2021", "2021",
"2021"), gameDate = c("2021-08-11T17:10:00Z", "2021-08-11T18:10:00Z",
"2021-08-11T18:10:00Z", "2021-08-11T20:10:00Z", "2021-08-11T20:10:00Z",
"2021-08-11T23:05:00Z"), officialDate = c("2021-08-11", "2021-08-11",
"2021-08-11", "2021-08-10", "2021-08-11", "2021-08-11"), isTie = c(FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE), gameNumber = c(1L, 1L, 1L,
1L, 1L, 1L), publicFacing = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE
), doubleHeader = c("N", "N", "N", "N", "N", "N"), gamedayType = c("P",
"P", "P", "P", "P", "P"), tiebreaker = c("N", "N", "N", "N",
"N", "N"), calendarEventID = c("14-632927-2021-08-11", "14-632904-2021-08-11",
"14-632935-2021-08-11", "14-632966-2021-08-11", "14-632959-2021-08-11",
"14-632922-2021-08-11"), seasonDisplay = c("2021", "2021", "2021",
"2021", "2021", "2021"), dayNight = c("day", "day", "day", "day",
"day", "night"), scheduledInnings = c(9L, 9L, 9L, 9L, 9L, 9L),
reverseHomeAwayStatus = c(FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE), inningBreakLength = c(120L, 120L, 120L, 120L, 120L,
120L), gamesInSeries = c(3L, 2L, 3L, 3L, 3L, 3L), seriesGameNumber = c(3L,
2L, 3L, 2L, 3L, 2L), seriesDescription = c("Regular Season",
"Regular Season", "Regular Season", "Regular Season", "Regular Season",
"Regular Season"), recordSource = c("S", "S", "S", "S", "S",
"S"), ifNecessary = c("N", "N", "N", "N", "N", "N"), ifNecessaryDescription = c("Normal Game",
"Normal Game", "Normal Game", "Normal Game", "Normal Game",
"Normal Game"), resumedFrom = c(NA, NA, NA, "2021-08-10T23:10:00Z",
NA, NA), resumedFromDate = c(NA, NA, NA, "2021-08-10", NA,
NA), rescheduleDate = c(NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_), rescheduleGameDate = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_), status.abstractGameState = c("Final", "Final",
"Final", "Final", "Final", "Final"), status.codedGameState = c("F",
"F", "F", "F", "F", "F"), status.detailedState = c("Final",
"Final", "Final", "Final", "Final", "Final"), status.statusCode = c("F",
"F", "F", "F", "F", "F"), status.startTimeTBD = c(FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE), status.abstractGameCode = c("F",
"F", "F", "F", "F", "F"), status.reason = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_), teams.away.score = c(0L, 1L, 5L, 7L, 7L,
5L), teams.away.isWinner = c(FALSE, FALSE, TRUE, FALSE, TRUE,
TRUE), teams.away.splitSquad = c(FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE), teams.away.seriesNumber = c(37L, 37L, 37L,
37L, 38L, 36L), teams.away.leagueRecord.wins = c(67L, 51L,
63L, 50L, 48L, 56L), teams.away.leagueRecord.losses = c(48L,
63L, 51L, 63L, 67L, 60L), teams.away.leagueRecord.pct = c(".583",
".447", ".553", ".442", ".417", ".483"), teams.away.team.id = c(145L,
115L, 147L, 120L, 146L, 116L), teams.away.team.name = c("Chicago White Sox",
"Colorado Rockies", "New York Yankees", "Washington Nationals",
"Miami Marlins", "Detroit Tigers"), teams.away.team.link = c("/api/v1/teams/145",
"/api/v1/teams/115", "/api/v1/teams/147", "/api/v1/teams/120",
"/api/v1/teams/146", "/api/v1/teams/116"), teams.home.score = c(1L,
5L, 2L, 8L, 0L, 2L), teams.home.isWinner = c(TRUE, TRUE,
FALSE, TRUE, FALSE, FALSE), teams.home.splitSquad = c(FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE), teams.home.seriesNumber = c(37L,
37L, 37L, 36L, 37L, 37L), teams.home.leagueRecord.wins = c(50L,
68L, 49L, 57L, 66L, 38L), teams.home.leagueRecord.losses = c(65L,
46L, 64L, 55L, 50L, 74L), teams.home.leagueRecord.pct = c(".435",
".596", ".434", ".509", ".569", ".339"), teams.home.team.id = c(142L,
117L, 118L, 121L, 135L, 110L), teams.home.team.name = c("Minnesota Twins",
"Houston Astros", "Kansas City Royals", "New York Mets",
"San Diego Padres", "Baltimore Orioles"), teams.home.team.link = c("/api/v1/teams/142",
"/api/v1/teams/117", "/api/v1/teams/118", "/api/v1/teams/121",
"/api/v1/teams/135", "/api/v1/teams/110"), venue.id = c(3312L,
2392L, 7L, 3289L, 2680L, 2L), venue.name = c("Target Field",
"Minute Maid Park", "Kauffman Stadium", "Citi Field", "Petco Park",
"Oriole Park at Camden Yards"), venue.link = c("/api/v1/venues/3312",
"/api/v1/venues/2392", "/api/v1/venues/7", "/api/v1/venues/3289",
"/api/v1/venues/2680", "/api/v1/venues/2"), content.link = c("/api/v1/game/632927/content",
"/api/v1/game/632904/content", "/api/v1/game/632935/content",
"/api/v1/game/632966/content", "/api/v1/game/632959/content",
"/api/v1/game/632922/content")), row.names = c(NA, 6L), class = "data.frame")
as a human being faced with two spreadsheets and asked to manually merge them by row, how would you approach the column name mismatch issue ?
ignore and proceed , would that work ?
it would be pretty easy to rename the columns of one based of the known column names of the other and thus align them (assuming it doesnt matter).
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.