切割后的因子抓取功能(Grabbing edges of factor after cut function)
当我用另一个向量剪切一个向量时,我得到了很多这样的因素:(0,100),(100,200)等。有没有办法得到这些因子中的一个,然后采取上限或下限?
ex:for(100,200)我想要一些方法来抓住100和200。
编辑:
> v <- cut(c(3,4,6,8), c(1,4,5,9,12)) > v [1] (1,4] (1,4] (5,9] (5,9] Levels: (1,4] (4,5] (5,9] (9,12] > v[1] [1] (1,4] Levels: (1,4] (4,5] (5,9] (9,12]我想要一些方法,当给出v [1]时,得到数字1和4。
When I cut one vector by another vector, I get a lot of factors like this: (0,100], (100,200], etc. Is there any way to get one of these factors and then take the upper or lower bound?
ex: for (100,200] I want some way to grab the 100 and the 200.
Edit:
> v <- cut(c(3,4,6,8), c(1,4,5,9,12)) > v [1] (1,4] (1,4] (5,9] (5,9] Levels: (1,4] (4,5] (5,9] (9,12] > v[1] [1] (1,4] Levels: (1,4] (4,5] (5,9] (9,12]I want some way, when given v[1], to get the numbers 1 and 4.
最满意答案
strsplit(gsub("\\[|\\]|\\(", "", as.character(v[1]) ) , ",")[[1]] #[1] "1" "4" strsplit(gsub("\\[|\\]|\\(", "", as.character(v[1]) ) , ",")[[1]] #[1] "1" "4"更多推荐
发布评论