Re: [R] data type for block data?

From: Stephen Tucker <brown_emu_at_yahoo.com>
Date: Mon, 18 Jun 2007 22:47:17 -0700 (PDT)


Hi Paul,

Hope this is what you're looking for:

## reading in text (the first 13 rows of cc from your posting)
## and using smaller indices [(3,8) instead of (10,40)]
## for this example

> cc <- "mode<-"(do.call(rbind,
+ strsplit(readLines(textConnection(txt))[-1],"[ ]{2,}"))[,-1], + "numeric")

> index <- c(3,8)
## (1) convert cc to data frame
## (2) split according to factors produced by cut()
## (3) apply data.matrix() to each element of list
##     produced by split() to convert back to numeric matrix

> s <- lapply(split(as.data.frame(cc),
+ f=cut(1:nrow(cc),breaks=c(-Inf,index,Inf))), + data.matrix)

## return result. now s[[1]] contains the first "block", ## s[[2]] contains the second "block", and so on.
> s

$`(-Inf,3]`
  V1 V2
1 1 26
2 2 27
3 3 28

$`(3,8]`
  V1 V2
4 4 29
5 5 30
6 6 31
7 7 32
8 8 33

$`(8, Inf]`

   V1 V2
9 9 34
10 1 27
11 1 28
12 2 30
13 3 34

> Dear All,
>
>
> I have a matrix with data that is not organised. I would like to go
> through this and extract it. Each feature has 2 vectors which express
> the data. I also have an index of the places where the data should be cut.
> eg.
> >class(cc)
> "matrix"
> >cc
> [,1] [,2]
> [1,] 1 26
> [2,] 2 27
> [3,] 3 28
> [4,] 4 29
> [5,] 5 30
> [6,] 6 31
> [7,] 7 32
> [8,] 8 33
> [9,] 9 34
> [10,] 1 27
> [11,] 1 28
> [12,] 2 30
> [13,] 3 34
> ect......
> > index
> [1] "10" "40"
>
>
> Is there a way to take cc[i:index[i-1],] to another format as to where
> each block could be worked on separately. ie so in one block would be
> rows1:10 the next block would be rows11:40 and so on.
>
> Thanks,
>
> Paul
>
>
>
> --
> Research Technician
> Mass Spectrometry
> o The
> /
> o Scripps
> \
> o Research
> /
> o Institute
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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_stat.math.ethz.ch 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. Received on Tue 19 Jun 2007 - 06:16:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Jun 2007 - 06:32:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.