Created
July 12, 2016 19:17
-
-
Save bhaskarvk/0b7a62b3cd2be6ff3426a39ba37d373d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l1 <- list(as.list(1:4), | |
as.list(11:15)) | |
l2 <- list(list('a.1'=1,'a.2'=2,'a.3'=3,'a.4'=4), | |
list('b.1'=1,'b.2'=2,'b.3'=3,'b.4'=4,'b.5'=5)) | |
lapply(l1,names) # should be nulls | |
lapply(l2,names) # should be 'a.1' ... | |
# Use copy so as to leave l1 intact | |
t1 <- l1 | |
for(i in 1:2) {names(t1[[i]]) <- names(l2[[i]])} # this works | |
lapply(t1,names) | |
# but... | |
t1 <- l1 # reset back to original copy | |
lapply(t1,names) # Just to verify that all are null | |
purrr::walk(1:2,function(x) names(t1[[x]]) <- l2[[x]]) # this doesn't work | |
lapply(t1,names) # All Nulls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment