r - create list with values between begin and end positions -
i have text file format
begin end 1 10 25 35 40 50 37 48 ... ...
i use these commands make list contains values between values 'begin' , 'end' column
x <- read.table("in.txt") result <- vector("list",486) for(i in 1:486){ result[[i]] <- c(x[i,1]:x[i,2]) } lapply(result, write, "out.txt", append=true, ncolumns = 1)
so result file 1 column values on different lines. want extra.
instead of input file 'begin' , 'end' column, have 2 columns, this:
begin end b 1 10 x 0 25 35 x 1 40 50 x 2 37 48 y 0
i want values of these other columns appear in output, this
position b 1 x 0 2 x 0 3 x 0 ... 10 x 0 ... 40 x 2 41 x 2 ... 37 y 0
how can change function, output looks this?
here's base answer:
lapply(1:nrow(x), function(u) cbind(position=x$begin[u]:x$end[u], x[u,3:4]))
hth
Comments
Post a Comment