R: report data from dataframe in other way

I have a question about generating a dataframe out of another dataframe. The new dataframe contains the same information as the old dataframe but reported the data in an other way. The dataframe to start with, looks like this:

> a
Gene.Symbol      miRNA
    Nap1l1       mmu-let-7a
    Napepld      mmu-let-7b
    Nat8l        mmu-let-7b
    Nceh1        mmu-let-7b
    Ncoa3        mmu-let-7a
    Ndst2        mmu-let-7a
    Ndst3        mmu-let-7a
    Nedd4l       mmu-let-7a
    Nedd4l       mmu-let-7b
    Nefm         mmu-let-7a

Now i want to convert the dataframe to a dataframe like below.

>b               mmu-let-7a    mmu-let-7b
    Nap1l1       1             0 
    Napepld      0             1
    Nat8l        0             1
    Nceh1        0             1
    Ncoa3        1             0
    Ndst2        1             0
    Ndst3        1             0
    Nedd4l       1             1
    Nefm         1             0

Can anyone help me with this? Many thanks! Regards Lisanne

Answers


Using reshape2:

require(reshape2)
df$z <- 1
dcast(df, Gene.Symbol ~ miRNA, value.var="z", fill=0)
#   Gene.Symbol mmu-let-7a mmu-let-7b
# 1      Nap1l1          1          0
# 2     Napepld          0          1
# 3       Nat8l          0          1
# 4       Nceh1          0          1
# 5       Ncoa3          1          0
# 6       Ndst2          1          0
# 7       Ndst3          1          0
# 8      Nedd4l          1          1
# 9        Nefm          1          0

Need Your Help

Base URL in Kohana 3

php kohana-3

How do I get the base URL in Kohana 3?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.