[R] plot cdf
Good Afternoon, I'm trying to create a cdf plot, with the following code.It works well, but I have little doubt, if you can help solve.When I create the plot, like the graph line would still not appear with point #cdf x<-table(Dataset$Apcode) View(s) hist(s) *plot(ecdf(x))* x<-137607 2 26625 3 5856 4 25992 5 30585 6 16064 7 9850 .. ... .. 186 52 -- View this message in context: http://r.789695.n4.nabble.com/plot-cdf-tp4633349.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot cdf
Thanks -- View this message in context: http://r.789695.n4.nabble.com/plot-cdf-tp4633349p4633515.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] graph displays
Good Afternoon, I'm trying to create a graph that displays the best way the following information. For instance organized by bar graph, A, B, C Source X1000s X600s X500s X250s X100s X50s X10s X5s X3s X1s 1 A 476375 116 125 129 131 131 131 131 2 B 3764451125 19 61 131 186 186 3 C 1762256612 29 91 171 186 186 thanks -- View this message in context: http://r.789695.n4.nabble.com/graph-displays-tp4634448.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] graph displays
Good morning, Thanks for help. I can explain better what I am trying to do. I'm trying to read data from a file, separated by a tab, with the following code. Dataset<-read.table("C:/Users/Administrator/Desktop/R/graph.txt",sep="\t", quote="\"",header = TRUE) View(Dataset) dput(Dataset) > View(Dataset) > dput(Dataset) structure(list(Source = structure(1:3, .Label = c("A", "B", "C" ), class = "factor"), X1000s = c(47L, 37L, 17L), X600s = c(63L, 64L, 62L), X500s = c(75L, 45L, 25L), X250s = c(116L, 11L, 66L ), X100s = c(125L, 25L, 12L), X50s = c(129L, 19L, 29L), X10s = c(131L, 61L, 91L), X5s = c(131L, 131L, 171L), X3s = c(131L, 186L, 186L ), X1s = c(131L, 186L, 186L)), .Names = c("Source", "X1000s", "X600s", "X500s", "X250s", "X100s", "X50s", "X10s", "X5s", "X3s", "X1s"), class = "data.frame", row.names = c(NA, -3L)) > Dataset Source X1000s X600s X500s X250s X100s X50s X10s X5s X3s X1s 1 A 476375 116 125 129 131 131 131 131 2 B 3764451125 19 61 131 186 186 3 C 1762256612 29 91 171 186 186 the idea is to get a graph like this excel, but in R, as I'm still in the learning phase of the R, I have little knowledge how to do http://imageshack.us/photo/my-images/51/testlt.png/ -- View this message in context: http://r.789695.n4.nabble.com/graph-displays-tp4634448p4634488.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Subtract Date Between columns
Hello I have this little dataset, my goal is create one column in the data.frame with between the diference DataTime and Duration. I'm using the next code to make do this TIME_STAMP SESSIONTIMETime TimeStart 1162343932 83202006-10-31 19:01:34 2006-10-31 16:42:54 11623432155922006-10-31 19:02:04 2006-10-31 18:52:12 116234146511875 2006-10-31 19:02:27 2006-10-31 15:44:32 1162339324118 2006-10-31 19:03:01 2006-10-31 19:03:03 11623393812 Dataset$Time<-as.POSIXlt(TIME_STAMP, origin="1970-01-01", tz="America/New_York") temp1<-Dataset$Time-Dataset$SESSIONTIME Dataset$TimeStart<-as.POSIXlt(temp1, origin="1970-01-01", tz="America/New_York") I don't understand why changed the data in column TimeStar on 4 register Thanks -- View this message in context: http://r.789695.n4.nabble.com/Subtract-Date-Between-columns-tp4474466p4474466.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Average row and column
Hello I have this code for the count the occurrences between V_source and V_destine, its can possible make the same, but in local the total the occurrences to appear the mean or the minimum Dataset df.v_source df.v_destine df.dif 1 33 4 2 77 0 3 66 0 4 34 35 5 44 56 6 43 61 7 33300 8 33 27 9 33 33 1033 87 1134 49 minimum<-: appears to this 1 2 3 4 5 6 7 1 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 3 0 0 4 35 0 0 0 4 0 0 61 56 0 0 0 5 0 0 0 0 1 0 0 6 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 -- View this message in context: http://r.789695.n4.nabble.com/Average-row-and-column-tp4474524p4474524.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Average row and column
Sorry, I ll explain better. For example in the next dataset, x<-data.frame(v_source=3,v_destine=3,dist=4) x<-rbind(x,data.frame(v_source=7,v_destine=7,dist=0)) x<-rbind(x,data.frame(v_source=6,v_destine=6,dist=0)) x<-rbind(x,data.frame(v_source=4,v_destine=4,dist=56)) x<-rbind(x,data.frame(v_source=4,v_destine=3,dist=61)) x<-rbind(x,data.frame(v_source=3,v_destine=3,dist=300)) x<-rbind(x,data.frame(v_source=3,v_destine=3,dist=27)) x<-rbind(x,data.frame(v_source=3,v_destine=3,dist=87)) x<-rbind(x,data.frame(v_source=3,v_destine=4,dist=49)) when execute this instruction gives res<-table(x$v_source,x$v_destine) 3 4 6 7 3 4 1 0 0 4 1 1 0 0 6 0 0 1 0 7 0 0 0 1 my idea is that if possible, is an array like this, but instead of having the frequency, appears the minimum or average. Appears 4 times, instead of the value displayed in the matrix 4, show the average values. In the case mean 104.5 average(4, 300,27,87). The idea was to the average value for each combination of row and column. the idea is to get something like the following matrix. 3 4 6 7 3 104.5 49 0 0 4 61 56 0 0 6 00 1 0 7 00 0 1 -- View this message in context: http://r.789695.n4.nabble.com/Average-row-and-column-tp4474524p4475146.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Average row and column
Sorry, I ll explain better. For example in the next dataset, x<-data.frame(v_source=3,v_destine=3,dist=4) x<-rbind(x,data.frame(v_source=7,v_destine=7,dist=0)) x<-rbind(x,data.frame(v_source=6,v_destine=6,dist=0)) x<-rbind(x,data.frame(v_source=4,v_destine=4,dist=56)) x<-rbind(x,data.frame(v_source=4,v_destine=3,dist=61)) x<-rbind(x,data.frame(v_source=3,v_destine=3,dist=300)) x<-rbind(x,data.frame(v_source=3,v_destine=3,dist=27)) x<-rbind(x,data.frame(v_source=3,v_destine=3,dist=87)) x<-rbind(x,data.frame(v_source=3,v_destine=4,dist=49)) when execute this instruction gives res<-table(x$v_source,x$v_destine) 3 4 6 7 3 4 1 0 0 4 1 1 0 0 6 0 0 1 0 7 0 0 0 1 my idea is that if possible, is an array like this, but instead of having the frequency having the minimum or average. appears 4 times, no lugar de aparecer o valor 4 na matriz, Appears 4 times, instead of the value displayed in the matrix 4, show the average value of all in the case mean 104.5 (4, 300,27,87). The idea was to the average value for each combination of row and column. the idea is to get something like the following matrix. 34 6 7 3 104.5 49 0 0 4 61 56 0 0 6 0 0 0 0 7 00 00 Thanks . -- View this message in context: http://r.789695.n4.nabble.com/Average-row-and-column-tp4474524p4475135.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Average row and column
Thank you. Works perfectly -- View this message in context: http://r.789695.n4.nabble.com/Average-row-and-column-tp4474524p4475438.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Save File after order
Hello, I'm trying to write the sorted data in a file of a data.frame, My question and my problem is that when I record in file adds a new column row.name, which apparently is the original position in the file. I wanted to write to the file without this column x<-data.frame(name="x1",Time=20) x<-rbind(x,data.frame(name="x2",Time=25)) x<-rbind(x,data.frame(name="x3",Time=23)) x<-rbind(x,data.frame(name="x2",Time=45)) x<-rbind(x,data.frame(name="x1",Time=25)) x<-rbind(x,data.frame(name="x1",Time=55)) x<-x[order(x$name),] View(x) write.csv(data.frame(x$name,x$Time), file = "~/Desktop/DatasetOrder.csv") In this momment save this name Time 1 x1 20 5 x1 25 6 x1 55 2 x2 25 4 x2 45 3 x3 23 The ideia is save name Time x1 20 x1 25 x1 55 x2 25 x2 45 x3 23 Thanks -- View this message in context: http://r.789695.n4.nabble.com/Save-File-after-order-tp4484539p4484539.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Save File after order
Thanks -- View this message in context: http://r.789695.n4.nabble.com/Save-File-after-order-tp4484539p4485370.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Unique in DataFrame
Hello, I have little doubt, and I do not think that the way I solve the problem is the best way to do it. The following is a small dataset x<-data.frame(city="Barcelona",sales=253639) x<-rbind(x,data.frame(city="Madrid",sales=223455)) x<-rbind(x,data.frame(city="Lisbon",sales=273633)) x<-rbind(x,data.frame(city="Madrid",sales=266535)) x<-rbind(x,data.frame(city="Barcelona",sales=258369)) x<-rbind(x,data.frame(city="Lisbon",sales=273633)) x<-rbind(x,data.frame(city="Barcelona",sales=22579)) x<-rbind(x,data.frame(city="Lisbon",sales=26333)) x<-rbind(x,data.frame(city="Barcelona",sales=253639)) x$num<-as.numeric(as.numeric(factor(x$city))) View(x) my problem and my doubts start here, I'm trying to create a list of cities and the code that was assigned in. x$num<-as.numeric(as.numeric(factor(x$city))) here seems to work fine, but the largest dataset repeats some values and hiding others, this is the correct way to present unique values in a column, and view the contents with other columns rescity<-x[unique(x$city),c(3,1)] rescity Thanks -- View this message in context: http://r.789695.n4.nabble.com/Unique-in-DataFrame-tp4488943p4488943.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unique in DataFrame
Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Unique-in-DataFrame-tp4488943p4489554.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Read File for Matrix with rownames
Good morning, Good morning, I'm trying to read the file into an array, with the following code. A<- as.matrix(read.csv("~/Desktop/Results/Cfile.csv", header = FALSE, sep=",")) The content of the file " ","1","2","3","4" "1", 484,43,67,54 "2",54,35,67,34 "3",69,76,78,55 "4",67,86,44,34 What I needed is that the first line was the name of the columns and the first column was the name of the lines. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Read-File-for-Matrix-with-rownames-tp4498280p4498280.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] copy the columns based on the code
Hello, I have two different dataset, and wanted to join the two. For example I have a table of codes of cities, and other with with the codes of travels, [source for the destine]. what he wanted was to have a new data.frame with all the information city<-data.frame(city="Barcelona",cod=1) city<-rbind(city,data.frame(city="Madrid",cod=2)) city<-rbind(city,data.frame(city="Lisbon",cod=3))) city<-rbind(city,data.frame(city="Milan",cod=4)) city<-rbind(city,data.frame(city="London",cod=5)) travel<-data.frame(pos=1,Source=1,Destine=2) travel<-rbind(travel,data.frame(pos=1,Source=1,Destine=3)) travel<-rbind(travel,data.frame(pos=2,Source=3,Destine=4)) travel<-rbind(travel,data.frame(pos=3,Source=2,Destine=4)) travel<-rbind(travel,data.frame(pos=4,Source=1,Destine=3)) #for example pos Source city Destine city_destine 1 1 Barcelona 2 Madrid 1 1 Barcelona 3 Lisbon 2 3 Lisbon 4 Milan 3 2 Madrid 4 Milan which the fastest way to do this. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/copy-the-columns-based-on-the-code-tp4505253p4505253.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] copy the columns based on the code
Thanks for the reply. I am using the function you gave me. complete.travel<-merge(travel, city, by.x = "Source", by.y = "cod", all = TRUE) complete.travel<-merge(travel, city, by.x = "Destine", by.y = "cod", all = TRUE The problem is that it gives the result that I want The idea is based on the column of source and intended Identify the cities and put a new data structure The idea is something like this. pos Source city Destine city_destine 1 1 Barcelona 2 Madrid 1 1 Barcelona 3 Lisbon 2 3 Lisbon 4 Milan 3 2 Madrid 4 Milan -- View this message in context: http://r.789695.n4.nabble.com/copy-the-columns-based-on-the-code-tp4505253p4505939.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] copy the columns based on the code
thanks, is working -- View this message in context: http://r.789695.n4.nabble.com/copy-the-columns-based-on-the-code-tp4505253p4506128.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] copy the columns based on the code
thanks for the reply, But does not the results I need. What is confusing is that when making the first merge it gives only two cities when it should take three travel<-data.frame(pos=1,Source=1,Destine=2) travel<-rbind(travel,data.frame(pos=1,*Source=1*,Destine=3)) travel<-rbind(travel,data.frame(pos=2,*Source=3*,Destine=4)) travel<-rbind(travel,data.frame(pos=3,*Source=2*,Destine=4)) travel<-rbind(travel,data.frame(pos=4,*Source=1*,Destine=3)) temp1 <- merge(travel, city, by.x='Source', by.y='cod') >temp1 () Source pos Destine city 1 *1* 1 2 Barcelona 2 1 1 3 Barcelona 3 1 4 3 Barcelona 4 *2 * 3 4Madrid -- View this message in context: http://r.789695.n4.nabble.com/copy-the-columns-based-on-the-code-tp4505253p4506102.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R extract parts
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 poscommunications source v_destine 7 1 109 2222 7 2 100 2222 7 3 214 2222 7 4 322 2222 7 5 69920 22 161 7 6 68 16197 7 7 196 9797 7 8 427 9722 7 9460 2222 7 10 307 2222 7 11 9582 2222 7 12 55428 2222 7 139192 2222 7 14 19 2222 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. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] copy the columns based on the code
Hello, this code, works perfectly temp <- merge(travel, city, by.x="Source", by.y="cod") result <- merge(temp, city, by.x="Destine", by.y="cod") The problem was the construction of the data frame, had a parenthesis in city<-rbind(city,data.frame(city="Lisbon",cod=3))), I tried to delete the post, but i don't could. As I have little experience in R, I still do some mistakes. I use read.table to load the data frame, the way in the post, it was quickly that i found to describe the problem. The forum has been a great help for me. Thanks -- View this message in context: http://r.789695.n4.nabble.com/copy-the-columns-based-on-the-code-tp4505253p4509340.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R extract parts
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. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extract index column the max
Hello, I have this data.frame, and i need the value the column where the value in matrix is maximum res3 77 86 93 106 161 77 20 0 0 1 0 86 1 12 1 2 1 93 0 2 3 3 0 106 0 4 3 18 0 161 0 0 0 1 55 I use this d<-which(res3==max(res3), arr.ind=T) > d row col 161 5 5 how do I return only the value 161 Thanks -- View this message in context: http://r.789695.n4.nabble.com/Extract-index-column-the-max-tp4512573p4512573.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] copy matrix another matrix
> results val_user v_source v_destine count average 1 7 2222 4 186.25 2 7 2222 2 383.50 3 7 2222 1 19.00 4 7 9797 1 196.00 5 7 16197 1 68.00 6 7 22 130 1 219.00 7 7 130 130 1 219.00 8 8 2222 1 28.00 9 8 2222 19.00 108 9722 1 427.00 …... #create matrix hits matrix_hits<-matrix(0,nrow=nrow(resumo),ncol=nrow(resumo),) colnames(matrix_hits)<-resumo$Apcode rownames(matrix_hits)<-resumo$Apcode users<-levels users<-data.frame(levels(factor(results$val_user)) for(val_user in users) { results_user <- results[results$val_user==val_user,] r1<-tapply(results_user$count, list(results_user$v_source,results_user$v_destine),sum ) r1[is.na(r1)] <- 0 for(i in 1:nrow(r1)) { for(j in 1:ncol(r1)) { print(paste(rownames(r1)[i],colnames(r1)[j])) col<-colnames(r1)[j] row<-rownames(r1)[i] hits<-r1[row,col] matrix_hits[col,row]<- as.numeric(matrix_hits[col,row])+hits } } } View(matrix_hits) is there any way to do this more effectively, maintaining the loop for the user, updating only matrix hits with results the matrix r1 Thanks -- View this message in context: http://r.789695.n4.nabble.com/copy-matrix-another-matrix-tp4515909p4515909.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Order sapply
Good Afternoon, I have the following code, but it seems that something must be doing wrong, because it is giving the results I want. The idea is to create segments while the value of Commutation is less than 1000. for example, from the small set of data below text=" val_user posvv_starv_endcommutationv_source v_destine 11 96-961173438391117343839109696 32126-12611725017291172501532197126126 33126-3511744041771172501909190226812635 3435-5611744042521174404221313556 3556-991174404295117440429505699 3699-921174404536117440453519992 3792-991174404660117440465829299 3899-431174405442117440544209943 3943-991174405545117440554414399 31099-431174405581117440558109943 31143-991174405836117440583604399 31299-431174405861117440586109943 31343-991174405875117440587504399 318101-113117441021511744102141101113 319113-3611744102611174410261011336 32036-601174410268117441026803660 32160-1011174660357117441102024933760101 322101-191117466620511746621194086101191 323191-1961174666278117466626513191196 324196-911746663981174666366321969 3259-101117515413911746671444869959101 326101-371175160182117515973444810137 32737-5511751602561175160257-13755 4111-11121630483612163041277091111 4211-1112163701541216312995571591111 4311-11121637323412163727994351111 4411-11121637397412163733736011111 4511-111216382659121637927733821111 4611-111216397081121639520118801111 4711-11121639733912163971312081111 4811-11121663064912163992352314141111 4911-111216637080121663154155391111 41011-111216646563121664076358001111 41111-111216656338121665163547031111 " df1 <-read.table(textConnection(text), header=TRUE) inx <- df1$commutation > 1000 comm1000 <- cumsum(inx) result <- split(df1[!inx, ], list(comm1000[!inx], df1$v_source[!inx], df1$v_destine[!inx])) result <- sapply(result, function(x) c(x$val_user[1], x$v_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", "v_source", "v_destine", "count", "average") attr(result, "na.action") <- NULL attr(result, "class") <- NULL results_user<-data.frame(result) View(results_user) This give: user v_source v_destine count Min Max average but the results I want: user v_source v_destine count Min Max average 1 96 96 1 0 0 0.000 3 126 126 1 197 197 197.000 3 35 56 1 31 31 31.000 …. I think there is a problem in the order of the different blocks, I don’t understand, how is that data are organized. The idea is to keep the organization of the file near the original. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Order-sapply-tp4537496p4537496.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Order sapply
Good Afternoon, I get it, my question was really how the data were organized, I thought I was doing something wrong. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Order-sapply-tp4537496p4542518.html Sent from the R help mailing list archive at Nabble.com. __ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.