1

I have a list, and its head is:

$AK
    hospital state
NA     <NA>  <NA>

$AL
                         hospital state
20 D W MCMILLAN MEMORIAL HOSPITAL    AL

$AR
                            hospital state
20 ARKANSAS METHODIST MEDICAL CENTER    AR

$AZ
                              hospital state
20 JOHN C LINCOLN DEER VALLEY HOSPITAL    AZ

$CA
                hospital state
20 SHERMAN OAKS HOSPITAL    CA

$CO
                    hospital state
20 SKY RIDGE MEDICAL CENTER    CO

I want to merge this list to a matrix, like this:

                              hospital state
AK                                <NA> AK
AL      D W MCMILLAN MEMORIAL HOSPITAL AL
AR   ARKANSAS METHODIST MEDICAL CENTER AR
AZ JOHN C LINCOLN DEER VALLEY HOSPITAL AZ
CA               SHERMAN OAKS HOSPITAL CA
CO            SKY RIDGE MEDICAL CENTER CO

notice: the first line of the matrix is different from the first item in the list. In the list, the state of the first item is <NA>, but the state of the first line in the matrix is AK. It is that merge the list's factor and the "hospital" in the list. What should I do?

And what if I want to merge the items in the list into a matrix?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Vansiee
  • 59
  • 9

1 Answers1

0

We can use rbind the 'lst' elements by using do.call

do.call(rbind, lst)
akrun
  • 874,273
  • 37
  • 540
  • 662
  • Could you kindly remove your answer, as you marked it as duplicated? –  Mar 01 '16 at 07:51
  • Because by closing the question, only your answer remains. You don't allow other to post an answer. –  Mar 01 '16 at 08:38
  • @Pascal Look, you posted the dupe link and somebody else have already suggested it as a dupe before I duped it. – akrun Mar 01 '16 at 08:40
  • @Pascal Are you saying that when you comment with a dupe link, I shouldn't dupe it? Come on, this is crazy! – akrun Mar 01 '16 at 08:42
  • I am saying that when you accept the dupe, you cannot keep your only answer. It is not fair. –  Mar 01 '16 at 08:43
  • @Pascal But, you can post an answer (if you were so concerned about my only answer). Look, I didn't even think about this when I closed it. I was only being a loyal, dutiful SO community member. – akrun Mar 01 '16 at 08:46
  • @Pascal That's up to me. Also, it's kind of doing a disservice to the person who posted the question. I answered it before you posted the link. – akrun Mar 01 '16 at 08:47
  • @Pascal If that is the case, [this](http://stackoverflow.com/questions/35717491/how-to-delete-dataframes-row-with-3-of-5-equal-element) is also a dupe. – akrun Mar 01 '16 at 08:48
  • Yes, also a dupe. The question is not regarding the OP. The question is once you posted an answer, don't accept the dupe ans freeze the question. If you do so, remove your answer. –  Mar 01 '16 at 08:49
  • 1
    Take it easy. It's my fault, I don't find the answer before. But I think we should not abuse our right of vote. The answer is right, and I am grateful for you both. By the way, should I delete this question? – Vansiee Mar 01 '16 at 08:54
  • @Vansiee You don't have to delete the question as no matter if it is a dupe or not, it will increase the chances of finding an answer to this kind of question when somebody search on the google. – akrun Mar 01 '16 at 08:58
  • @akrun Thank you very much! I think so. When I google my question, I didn't find the answer I want, so I asked. Maybe my google skill is not good. Hope my question will help others whose google skill is not good enough. – Vansiee Mar 01 '16 at 09:03
  • @Vansiee You are completely right. I also find it very difficult to find dupes when using some keywords. – akrun Mar 01 '16 at 09:06
  • 1
    @Pascal Although my question is dup, I think the form of my question is helpful for the freshman whose google skill is not good enough. And akrun's answer is what I want, which maybe others want, and it will not cause bad result. I hope you can cancel your downvote. Thank you. – Vansiee Mar 01 '16 at 09:08
  • @Vansiee It's okay. I don't care much about the votes. My happiness comes from helping people. – akrun Mar 01 '16 at 09:10
  • 1
    @Pascal What's more, if there is only one form of one kind question, isn't it hard for everyone to get what they want? After all, there are a thousand Hamlets in a thousand people's eyes. So, I hope you could reconsider your downvote. Thank you. – Vansiee Mar 01 '16 at 09:13