John Chrysostom
John Chrysostom

Reputation: 3983

Assign a list to the value of one element of another list

I want to make the value of a list element equal to another list, like so...

list_one <- as.list(c(A = NA, B = NA))
list_two <- as.list(c(C = 4, D = 5))

list_one['A'] <- list_two

This is throwing the following warning:

Warning message:
In list_one["A"] <- list_two :
  number of items to replace is not a multiple of replacement length

How do I properly make list_two a sub-list of list_one so that I don't get this warning?

Upvotes: 0

Views: 65

Answers (1)

akrun
akrun

Reputation: 887881

Use [[ instead of [

list_one[['A']] <- list_two

Upvotes: 2

Related Questions