named
Combine/merge lists by elements names
You can do: keys <- unique(c(names(lst1), names(lst2))) setNames(mapply(c, lst1[keys], lst2[keys]), keys) Generalization to any number of lists would require a mix of do.call and lapply: l <- list(lst1, lst2, lst1) keys <- unique(unlist(lapply(l, names))) setNames(do.call(mapply, c(FUN=c, lapply(l, `[`, keys))), keys)
How do I extract just the number from a named number (without the name)?
For a single element like this, use [[ rather than [. Compare: coefficients(out)[“newx”] # newx # 1 coefficients(out)[[“newx”]] # [1] 1 More generally, use unname(): unname(coefficients(out)[c(“newx”, “(Intercept)”)]) # [1] 1.0 1.5 head(unname(mtcars)) # NA NA NA NA NA NA NA NA NA NA NA # Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 … Read more