[R] data frame pointers?

arun smartpink111 at yahoo.com
Thu Oct 24 03:50:57 CEST 2013


You may try:
df <-
data.frame(case=c("case_1","case_1","case_2","case_3"), gene=c("gene1","gene1","gene1","gene2"), issue=c("nsyn","amp","del","UTR"), stringsAsFactors=FALSE)
res <- dcast(df,gene~case,value.var="issue",list)
#   gene    case_1 case_2 case_3
#1 gene1 nsyn, amp    del       
#2 gene2                     UTR


On Wednesday, October 23, 2013 7:38 PM, Jon BR <jonsleepy at gmail.com> wrote:
    I've been running several programs in the unix shell, and it's time to
combine results from several different pipelines.  I've been writing shell
scripts with heavy use of awk and grep to make big text files, but I'm
thinking it would be better to have all my data in one big structure in R
so that I can query whatever attributes I like, and print several
corresponding tables to separate files.

I haven't used R in years, so I was hoping somebody might be able to
suggest a solution or combinatin of functions that could help me get

Right now, I can import my data into a data frame that looks like this:

df <-
> df
    case  gene issue
1 case_1 gene1  nsyn
2 case_1 gene1   amp
3 case_2 gene1   del
4 case_3 gene2   UTR

I'd like to cook up some combination of functions/scripting that can
convert a table like df to produce a list or a data frame/ matrix that
looks like df2:

> df2
        case_1 case_2 case_3
gene1 nsyn,amp    del      0
gene2        0      0    UTR

I can build df2 manually, like this:

but obviously do not want to do this by hand; I want R to generate df2 from

Any pointers/ideas would be most welcome!


    [[alternative HTML version deleted]]

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list