Hi I am trying to print out means, STDs and histograms under two sets of factors. I can manage it for one set - see below but not for two sets. That is, I want ot print out the mean STD and Histogram for each ITEM code within each DELIVERABLE code. In addition I can only get to view the histogram for the last item. How do you get R to stop overriding the histogram for eg level 1 for factor 1 by level 2 of factor 1? thanks X11() Indat <- read.table ("C:/testdata.txt",header=T) B <- c(Indat[,1],Indat[,2],Indat[,3],Indat[,4],Indat[,5]) y <- Indat[,5]/Indat[,4] DELIV <- Indat[,1] ITEM <- Indat[,3] Df1 <- factor(DELIV) Df2 <- factor(ITEM) d1 <- tapply(y,Df1, mean) d2 <- tapply(y, Df1,sd) d3 <- tapply(y, Df1,max) d4 <- tapply(y, Df1,hist) print(d1) print(d4)
"Briggs, Meredith M" <Meredith.Briggs at team.telstra.com> writes:> Hi > > > I am trying to print out means, STDs and histograms under two sets > of factors. I can manage it for one set - see below but not for two > sets. That is, I want ot print out the mean STD and Histogram for > each ITEM code within each DELIVERABLE code.Tapply accepts a list of factors, tapply(y,list(Df1,Df2),mean), and so forth (and the help page does say so...).> In addition I can only get to view the histogram for the last item.You do get to view the others, just not for very long ;-)> How do you get R to stop overriding the histogram for eg level 1 for > factor 1 by level 2 of factor 1?par(ask=TRUE) is one possible answer. Others include - turning on plot history (in the Windows GUI) or use recordPlot/replayPlot - switching graphics device to a file and viewing it later - opening a separate graphics device for each histogram - setting up for multiple plots on the same page.> > thanks > > > > > X11() > > Indat <- read.table ("C:/testdata.txt",header=T) > > B <- c(Indat[,1],Indat[,2],Indat[,3],Indat[,4],Indat[,5]) > y <- Indat[,5]/Indat[,4] > DELIV <- Indat[,1] > ITEM <- Indat[,3] > Df1 <- factor(DELIV) > Df2 <- factor(ITEM) > > d1 <- tapply(y,Df1, mean) > d2 <- tapply(y, Df1,sd) > d3 <- tapply(y, Df1,max) > d4 <- tapply(y, Df1,hist) > > print(d1) > print(d4) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Dear Meredith, At 10:08 AM 2/6/2004 +1100, Briggs, Meredith M wrote:>I am trying to print out means, STDs and histograms under two sets of >factors. I can manage it for one set - see below but not for two sets. >That is, I want ot print out the mean STD and Histogram for each ITEM code >within each DELIVERABLE code.You can use commands such as tapply(y, list(deliv=Df1, item=Df2), mean).> In addition I can only get to view the histogram for the last item. How > do you get R to stop overriding the histogram for eg level 1 for factor > 1 by level 2 of factor 1?If you set par(ask=TRUE) after opening the graphics device, then you will be prompted to press the enter key before each plot. Alternatively, you could do something like par(mfrow=c(nlevels(Df1), nlevels(Df2)) tapply(y, list(Df1, Df2), function(y) hist(y, main="")) to get an array of histograms (though the labelling leaves something to be desired). I hope this helps, John>thanks > > > > >X11() > >Indat <- read.table ("C:/testdata.txt",header=T) > >B <- c(Indat[,1],Indat[,2],Indat[,3],Indat[,4],Indat[,5]) >y <- Indat[,5]/Indat[,4] >DELIV <- Indat[,1] >ITEM <- Indat[,3] >Df1 <- factor(DELIV) >Df2 <- factor(ITEM) > >d1 <- tapply(y,Df1, mean) >d2 <- tapply(y, Df1,sd) >d3 <- tapply(y, Df1,max) >d4 <- tapply(y, Df1,hist) > >print(d1) >print(d4) > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox
Apparently Analagous Threads
- Best way/practice to create a new data frame from two given ones with last column computed from the two data frames?
- merging or joining 2 dataframes: merge, rbind.fill, etc.?
- Help with loop
- merging several dataframes from a list
- rbind: inconsistent behaviour with empty data frames?