Good Afternoon,
I believe that my to the problem, the R has a more effective solution.
in place the use the loop
I have the following set of data, and needs to extract some sections.
user pos communications source v_destine
7 1 109 22 22
7 2 100 22 22
7 3 214 22 22
7 4 322 22 22
7 5 69920 22 161
7 6 68 161 97
7 7 196 97 97
7 8 427 97 22
7 9 460 22 22
7 10 307 22 22
7 11 9582 22 22
7 12 55428 22 22
7 13 9192 22 22
7 14 19 22 22
my idea is to arise when a value greater than 1000 communications able to
extract some data.
In the example data set, is valued at over 1000 in the position 11,12,13.
my idea is to get results like this:
user, sector, source, destine, count, average
7 1 22 22 4 186.25 #
(109+100+214+322)
7 2 161 97 1 68
7 2 97 97 1 196
7 2 97 22 1 427
7 2 22 22 2 383
--
View this message in context:
http://r.789695.n4.nabble.com/R-extract-parts-tp4509042p4509042.html
Sent from the R help mailing list archive at Nabble.com.
Hello,> > my idea is to get results like this: > user, sector, source, destine, count, average > 7 1 22 22 4 186.25 # > (109+100+214+322) > 7 2 161 97 1 68 > 7 2 97 97 1 196 > 7 2 97 22 1 427 > 7 2 22 22 2 383 >Your second column, 'sector', comes from where? What is it? Without it, try this. text=" user pos communications source v_destine 7 1 109 22 22 7 2 100 22 22 7 3 214 22 22 7 4 322 22 22 7 5 69920 22 161 7 6 68 161 97 7 7 196 97 97 7 8 427 97 22 7 9 460 22 22 7 10 307 22 22 7 11 9582 22 22 7 12 55428 22 22 7 13 9192 22 22 7 14 19 22 22 " df1 <- read.table(textConnection(text), header=TRUE) inx <- df1$comm > 1000 comm1000 <- cumsum(inx) result <- split(df1[!inx, ], list(comm1000[!inx], df1$source[!inx], df1$v_destine[!inx])) result <- sapply(result, function(x) c(x$user[1], x$source[1], x$v_destine[1], nrow(x), mean(x$comm))) result <- na.exclude(t(result)) rownames(result) <- 1:nrow(result) colnames(result) <- c("user", "source", "v_destine", "count", "average") attr(result, "na.action") <- NULL attr(result, "class") <- NULL result Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/R-extract-parts-tp4509042p4510566.html Sent from the R help mailing list archive at Nabble.com.
Thank you,
Works perfectly.
When the column sector, is the value of lines in the example has six
sectors
--
View this message in context:
http://r.789695.n4.nabble.com/R-extract-parts-tp4509042p4511689.html
Sent from the R help mailing list archive at Nabble.com.