New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better column names when unnamed objects passed to merge #248

Closed
joshuaulrich opened this Issue Jun 17, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@joshuaulrich
Owner

joshuaulrich commented Jun 17, 2018

The column names of a merge() result can be monstrous if raw, unnamed objects are passed to merge(). This can occur when merge() is called via do.call(). For example:

data(sample_matrix)
x <- as.xts(sample_matrix)
d <- setNames(lapply(head(x, 2), function(x) { dimnames(x) <- NULL; x }), NULL)

# cbind.xts() calls merge.xts()
do.call(cbind, d)
           c.50.0397819115463..50.2304961977954.
2007-01-02                              50.03978
2007-01-03                              50.23050
           c.50.1177772350145..50.421876002125.
2007-01-02                             50.11778
2007-01-03                             50.42188
           c.49.9504146442813..50.2304961977954.
2007-01-02                              49.95041
2007-01-03                              50.23050
           c.50.1177772350145..50.3976663383861.
2007-01-02                              50.11778
2007-01-03                              50.39767

# zoo is similar
do.call(cbind, lapply(d, as.zoo))
           structure(c(50.0397819115463, 50.2304961977954), .Dim = c(2L, 
2007-01-02                                                       50.03978
2007-01-03                                                       50.23050
           structure(c(50.1177772350145, 50.421876002125), .Dim = c(2L, 
2007-01-02                                                      50.11778
2007-01-03                                                      50.42188
           structure(c(49.9504146442813, 50.2304961977954), .Dim = c(2L, 
2007-01-02                                                       49.95041
2007-01-03                                                       50.23050
           structure(c(50.1177772350145, 50.3976663383861), .Dim = c(2L, 
2007-01-02                                                       50.11778
2007-01-03                                                       50.39767

# matrix is a little nicer
do.call(cbind, lapply(d, as.matrix))
             X[[i]]   X[[i]]   X[[i]]   X[[i]]
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment