Re: [R] on how to make a skip-table

2013-09-17 Thread gildororonar
Quoting "Zhang Weiwu" : Jim Holtman asked me to elaborate the problem: It is a common problem in reading sparse variable-lenght record data file. Records are stored in file one next to another. The length of each record is known in advance, but a lot of them records are invalid,

Re: [R] how to find interval?

2013-09-17 Thread gildororonar
Quoting "PIKAL Petr" : diff(c(0,which(1:10 %in% c(3, 5, 6, 10 [1] 3 2 1 4 That solves the problem! Thanks. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org

[R] how to find interval?

2013-09-17 Thread gildororonar
I can do this: 1:10 %in% c(3, 5, 6, 10) [1] FALSE FALSE TRUE FALSE TRUE TRUE FALSE FALSE FALSE TRUE but what I wish to get is: [1] 3 2 1 4 let me explain: 3 # [1:3] ends with TRUE, i.e. FALSE FALSE TRUE 2 # [4:5] ends with TRUE, i.e. FALSE TRUE 1 # [6:6] ends with TRUE, i.e. TRUE 4 #

Re: [R] how to do this trimming/selecting in canonical R?

2013-09-14 Thread gildororonar
Quoting "Gabor Grothendieck" : Try this: library(sqldf) Thank you for introducing me to SQLDF package! I wasn't aware I could use SQL in R! Right now Arun sent me (forgetting to cc the list) a solution using apply/sapply, which inspired me of my own version: x <- which(sapply(seq_len

Re: [R] how to do this trimming/selecting in canonical R?

2013-09-14 Thread gildororonar
Quoting "Berend Hasselman" : Your trim-point in B is not unique (at least for the data you provided). Indeed. It's quit a surprise to me. I couldn't figure out why my evaluation expression results in multiple trimp-points In a general way, I am looking for x and y, where: A[x, condition]

[R] accumulate() function in R?

2013-09-14 Thread gildororonar
I came from Python, newly learning R. is there something like accumulate() in R? Example: accumulate([1,2,3,4,5]) --> 1 3 6 10 15 Or perhaps I should show the problem. The problem I am trying to solve, is to select elements from X until it accumulate to 30. My solution is: X = c(1,3,4,5

[R] how to do this trimming/selecting in canonical R?

2013-09-14 Thread gildororonar
This is better explained by example: A <- data.frame(force = sort(runif(10, 0, 1)), condition = sort(sample(0:100, 10))) B <- data.frame(counterforce = sort(runif(15, 0, 1), decreasing=T), condition = sort(sample(0:100, 15))) So we have: A force condition 1 0.03515542 1