[R] How can I make a list using aggregate function?

arun smartpink111 at yahoo.com
Thu Jun 28 20:34:43 CEST 2012


Hi,

The data is indeed very confusing.  It has four column names and five columns.  Assuming that zFEI is for fifth column, the fourth column is "Unknown1".

dat2<-read.table(text="
sequence              weight rsat. Unknown1  zFEl
 1    CTTTTCTTGTT    4.6  0.00058  -7.452 3.237
 2    ACTTTGAGGTG    4.1  0.00077  -7.169 3.114
 3    GTCTTGAACTC    4.8  0.00055  -7.506 3.260
 4  GCTTTGAAGAA    6.6  0.00019  -8.568 3.721
 5    GCTTTCAACAT    7.0  0.00014  -8.874 3.854
 6  TCCTTGTTCAT    3.5  0.00099  -6.918 3.004
",sep="",header=TRUE)

dat3<-aggregate(dat2$zFEl,by=list(dat2$sequence),quantile,probs=c(0.5,0.8,0.9))
dat4<-as.matrix(data.frame(dat3[,1],unlist(dat3[,2])))
colnames(dat4)<-NULL

dat5<-lapply(seq_len(nrow(dat4)),function(i) dat4[i,])
> dat5
[[1]]
[1] "ACTTTGAGGTG" "3.114"       "3.114"       "3.114"      

[[2]]
[1] "CTTTTCTTGTT" "3.237"       "3.237"       "3.237"      

[[3]]
[1] "GCTTTCAACAT" "3.854"       "3.854"       "3.854"      

[[4]]
[1] "GCTTTGAAGAA" "3.721"       "3.721"       "3.721"      

[[5]]
[1] "GTCTTGAACTC" "3.260"       "3.260"       "3.260"      

[[6]]
[1] "TCCTTGTTCAT" "3.004"       "3.004"       "3.004"  


The results I guess is fairly closer to the form you want to store as a list.
A.K.     






----- Original Message -----
From: Rui Barradas <ruipbarradas at sapo.pt>
To: sureshraj <sureshmallikaraj at gmail.com>
Cc: r-help at r-project.org
Sent: Thursday, June 28, 2012 12:09 PM
Subject: Re: [R] How can I make a list using aggregate function?

Hello,

Your data is a mess, with more columns than column names.
Use

# 20 to 100
dput(head(comb.data, 30)) # paste the output of this in a post.


Anyway, it seems that what you want is (untested)

aggregate(zFEl~sequence, data=comb.data, quantile, probs=c(0.5,0.8,0.9), 
na.rm=T)

Hope this helps,

Rui Barradas

Em 28-06-2012 15:10, sureshraj escreveu:
> Hi freind,
>   My data seems to be like , and data frame name is comb.data
> sequence               weight rsat.          zFEl
> 1    CTTTTCTTGTT    4.6   0.00058  -7.452 3.237
> 2    ACTTTGAGGTG    4.1   0.00077  -7.169 3.114
> 3    GTCTTGAACTC    4.8   0.00055  -7.506 3.260
> 4   GCTTTGAAGAA    6.6   0.00019  -8.568 3.721
> 5    GCTTTCAACAT    7.0   0.00014  -8.874 3.854
> 6   TCCTTGTTCAT    3.5   0.00099  -6.918 3.004
>
> So I need to use aggregate function based on sequence
> column(by=list(comb.data$sequence) for zFE column and I should need to store
> those results in lists..so result would be like
>   [[1]]
> CTTTTCTTGTT     2.3758   3.237
> [[2]]
> ACTTTGAGGTG   1.78977  -5.11768684
> [[3]]
>   GTCTTGAACTC    1.987455  1.260
> [[1]]
>   GCTTTGAAGAA  1.019  0.72541
> [[4]]
>   GCTTTCAACAT    0.0423   3.865754
> ...so I made a code like this,,but i am facing some bugs as i mentioned
> before,,could you please help to solve this one??I hope now you understand
> my query...
>
> the code is
> "data <- lapply(comb.data$zFE, function(x)
> aggregate(x,by=list(comb.data[["sequence"]]), quantile,
> probs=c(0.5,0.8,0.9), na.rm=T)) "
>
>
> Thanks,,
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-can-I-make-a-list-using-aggregate-function-tp4634714p4634764.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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