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.
Re: [R] Average row and column
On Mar 15, 2012, at 10:23 AM, MSousa wrote: 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 Oh, then you want 'tapply': > tapply(x$dist, list(x$v_source, x$v_destine), mean) 3 4 6 7 3 104.5 49 NA NA 4 61.0 56 NA NA 6NA NA 0 NA 7NA NA NA 0 -- 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. David Winsemius, MD West Hartford, CT __ 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
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
Hi > > 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 Your question is rather cryptic and I am rather confused what you really want. For row/column sum or mean you can use ?colSums or ?apply Regards Petr > > 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. __ 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.