[BioC] How to split data faster?

Christoph Bartenhagen Christoph.Bartenhagen at ukmuenster.de
Mon Apr 4 17:11:59 CEST 2011


Hi,

not sure if that's is the best way, but this is what came to my mind:

temp = strsplit(as.character(probe_int), split=",")
probe_int_s = matrix(sapply(temp, function(x) x[1]), nrow(probe_int), 
ncol(probe_int))
probe_int_b = matrix(sapply(temp, function(x) x[2]), nrow(probe_int), 
ncol(probe_int))


Hope this helps and does what you want.
Greetings,
Christoph


Am 04.04.2011 16:49, schrieb Ou, Jianhong:
> Hi all,
> I have data frame (probe_int) as:
>
> col1 col2 col3 ...
> 12,1 11,2 12,1 ...
> 10,1 11,1 11,2 ...
> ....
>
> I want to separate the data into two matrix by comma like:
> matrix1 (probe_int_s):
> col1 col2 col3 ...
> 12   11   12   ...
> 10   11   11   ...
> ...
>
> matrix2 (probe_int_b):
> col1 col2 col3 ...
> 1    2     1 ...
> 1    1     2 ...
> ....
>
> My code:
> for(i in 1:nrow(probe_int)){
> for(j in 1:ncol(probe_int)){
> temp<-strsplit(as.character(probe_int[i,j]),",")
> probe_int_s[i,j]<-as.numeric(temp[[1]][1])
> probe_int_b[i,j]<-as.numeric(temp[[1]][2])
> }
> }
>
> Is there any clean and grace methods to do that? Thanks.
>
> Yours sincerely,
>
> Jianhong Ou
>
> jianhong.ou at umassmed.edu<mailto:jianhong.ou at umassmed.edu>
>
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
>
>    


-- 
Christoph Bartenhagen
Institute of Medical Informatics
University of Münster
Domagkstraße 9
48149 Münster, Germany

phone: +49 (0)251/83-58367
mail:  Christoph.Bartenhagen at ukmuenster.de
web:   http://imi.uni-muenster.de



More information about the Bioconductor mailing list