0

I have a single object unique_object that I would like to bind to multiple objects object1, object2, object3 e.tc..., without transforming the multiple objects into a single list and I cannot figure out how I would do it:

I have tried passing cbind a list of the different objects, but I believe r interprets it as a single object comprised of all of those objects:

cbind(list(object1,object2,object3,object4 e.t.c... ), unique_object)

unique_object and object1, object2, etc. are of the same length.

user124123
  • 1,642
  • 7
  • 30
  • 50

1 Answers1

2

How about

lapply(list(object1,object2,object3,object4, ... ), cbind, unique_object)

This will return a list where unique_object is cbinded to each item in the original list.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • This does it but without assigning anything. – user124123 Jun 10 '14 at 14:10
  • +1! maybe you need a `list2env` step (even it is not recommended ) – agstudy Jun 10 '14 at 14:12
  • Well it returns an appropriate list, you can do with it as you like. R doesn't pass around references do you can't change the object in place. I guess I really don't understand what you want. – MrFlick Jun 10 '14 at 14:12
  • I'd like to keep the objects as lists, but unique_object bound to each them. – user124123 Jun 10 '14 at 14:15
  • 1
    @user1987097 Well, just replace the original list with the newly returned list. If you need any more help, please edit your question to include a specific [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) which makes it clear what the input and what the desired output is so we can test and evaluate suggestions. – MrFlick Jun 10 '14 at 14:21