I have a table statement that returns the following: [10.839,10.841] (10.841,10.843] (10.843,10.846] (10.846,10.848] (10.848,10.85] 0 0 0 0 1 (10.85,10.852] (10.852,10.854] (10.854,10.857] (10.857,10.859] (10.859,10.861] 0 0 0 0 0 What I want to do is get the upper bound value into a vector for each of the 10-buckets. (e.g. v<-c(10.841,10.843...) I'm totally clueless on how to proceed. Any help appreciated. TIA, Joe [[alternative HTML version deleted]]
Try this: v <- as.numeric(gsub("]|\\)", "", unlist(lapply(strsplit(names(tb), ","), "[", 2)))) Where tb is your table On Thu, Sep 4, 2008 at 10:20 AM, Trubisz, Joseph < jtrubisz@modernconsumer.com> wrote:> I have a table statement that returns the following: > > > > [10.839,10.841] (10.841,10.843] (10.843,10.846] (10.846,10.848] > (10.848,10.85] > > 0 0 0 0 > 1 > > (10.85,10.852] (10.852,10.854] (10.854,10.857] (10.857,10.859] > (10.859,10.861] > > 0 0 0 0 > 0 > > > > What I want to do is get the upper bound value into a vector for each of > the 10-buckets. > > (e.g. v<-c(10.841,10.843...) > > I'm totally clueless on how to proceed. > > Any help appreciated. > > > > TIA, > > Joe > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Here is one way:> y <- levels(cut(x,5)) > y[1] "(0.0124,0.209]" "(0.209,0.405]" "(0.405,0.601]" "(0.601,0.797]" "(0.797,0.993]"> sapply(y, function(x) sub(".*,(.*)]", "\\1", x))(0.0124,0.209] (0.209,0.405] (0.405,0.601] (0.601,0.797] (0.797,0.993] "0.209" "0.405" "0.601" "0.797" "0.993"> as.numeric(sapply(y, function(x) sub(".*,(.*)]", "\\1", x)))[1] 0.209 0.405 0.601 0.797 0.993>On Thu, Sep 4, 2008 at 9:20 AM, Trubisz, Joseph <jtrubisz at modernconsumer.com> wrote:> I have a table statement that returns the following: > > > > [10.839,10.841] (10.841,10.843] (10.843,10.846] (10.846,10.848] > (10.848,10.85] > > 0 0 0 0 > 1 > > (10.85,10.852] (10.852,10.854] (10.854,10.857] (10.857,10.859] > (10.859,10.861] > > 0 0 0 0 > 0 > > > > What I want to do is get the upper bound value into a vector for each of > the 10-buckets. > > (e.g. v<-c(10.841,10.843...) > > I'm totally clueless on how to proceed. > > Any help appreciated. > > > > TIA, > > Joe > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
See gsubfn.googlecode.com for more on the gsubfn package. Below we use strapply to pick out every string of digits and decimal points converting each to numeric returning a list of pairs and rbinding that list into a matrix.> x <- c("[10.839,10.841]", "(10.841,10.843]", "(10.843,10.846]", "(10.846,10.848]", "(10.848,10.85]") > library(gsubfn) > strapply(x, "[0-9.]+", as.numeric, simplify = rbind)[,1] [,2] [1,] 10.839 10.841 [2,] 10.841 10.843 [3,] 10.843 10.846 [4,] 10.846 10.848 [5,] 10.848 10.850 On Thu, Sep 4, 2008 at 9:20 AM, Trubisz, Joseph <jtrubisz at modernconsumer.com> wrote:> I have a table statement that returns the following: > > > > [10.839,10.841] (10.841,10.843] (10.843,10.846] (10.846,10.848] > (10.848,10.85] > > 0 0 0 0 > 1 > > (10.85,10.852] (10.852,10.854] (10.854,10.857] (10.857,10.859] > (10.859,10.861] > > 0 0 0 0 > 0 > > > > What I want to do is get the upper bound value into a vector for each of > the 10-buckets. > > (e.g. v<-c(10.841,10.843...) > > I'm totally clueless on how to proceed. > > Any help appreciated. > > > > TIA, > > Joe > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >