search for: addmargins

Displaying 20 results from an estimated 43 matches for "addmargins".

2006 Feb 14
1
addmargins
> addmargins(UCBAdmissions, FUN = list(Total=sum)) works with no problems, but consider: > myFUN <- list(Total=sum) > addmargins(UCBAdmissions, FUN = myFUN) Error in "names<-.default"(`*tmp*`, value = "") : names() applied to a non-vector Is this a bug? > R.ve...
2013 Apr 10
2
Table with n(%) formatting: A better way to do this?
...ogress as an R programmer. Ultimately want to have code that I can turn into a function. Will then use the output produced to make tables using odfWeave and Sweave/knitr. Thanks, Paul breaks <- as.data.frame(lapply(warpbreaks, function(x) rep(x, warpbreaks$breaks))) Freq <- with(breaks, addmargins(table(wool, tension), 2)) Prop <- round( prop.table(Freq, 2) * 100, 2 ) Freq <- addmargins(Freq, 1) Prop <- addmargins(Prop, 1) require(odfWeave) class(Freq) <- "character" class(Prop) <- "character" FreqProp <- matrixPaste(Freq, "(", Prop, "%)&...
2018 Feb 03
2
find unique and summerize
Thank you so much Rui. 1. How do I export this table to excel file? I used this tbl1 <- table(Country, IDNum) tbl2=addmargins(tbl1) write.xlsx(tbl2,"tt1.xlsx"),sheetName="summary", row.names=FALSE) The above did not give me that table. 2. I want select those unique Ids that do have records in all countries. From the above data set, this ID "FIN1540166" should be excluded from the s...
2006 Jun 29
2
zero.print in print.table after adding margins
The function addmargins() adds margins to a table, but returns a matrix. But even after converted to a table the print.zero="." option of print.table() does not work: > x <- sample( 1:7, 20, replace=T ) > y <- sample( 1:7, 20, replace=T ) > tt <- table( x, y ) > tx <- as.table( addmargin...
2006 Jun 29
2
zero.print in print.table after adding margins
The function addmargins() adds margins to a table, but returns a matrix. But even after converted to a table the print.zero="." option of print.table() does not work: > x <- sample( 1:7, 20, replace=T ) > y <- sample( 1:7, 20, replace=T ) > tt <- table( x, y ) > tx <- as.table( addmargin...
2004 Dec 13
3
Percentages in contingency tables *warning trivial question*
...N % N % N % Total 50 100 50 100 100 100 Sex: M 23 46 27 54 50 50 etc... I hesitate even more to mention it here, but I am thinking of something along the lines of PROC TABULATE in SAS. The closest I have found in the documentation I have read so far is an example given in the help for "addmargins": Bee <- sample( c("Hum","Buzz"), 177, replace=TRUE ) Sea <- sample( c("White","Black","Red","Dead"), 177, replace=TRUE ) ... # Weird function needed to return the N when computing percentages sqsm <- function( x ) sum(...
2012 Jun 26
5
chisq.test
...xample:         tabele <- matrix(c(11, 3, 3, 18, 3, 6, 5, 21), ncol = 4, byrow = TRUE)         dimnames(tabela) <- list(         "SEX" = c("M","F"),         "HAIR" = c("Brown", "Black", "Red", "Blonde"))         addmargins(tabele)         prop.table(tabele)         chisq.test(tabele) Please, give me an advice / suggestion / recommendation. Thanks a lot to all, OV [[alternative HTML version deleted]]
2018 Feb 05
0
find unique and summerize
...radas at sapo.pt >> <mailto:ruipbarradas at sapo.pt>> wrote: >> >> Hello, >> >> As for the first question, instead of writing a xlsx file, maybe it >> is easier to write a csv file and then open it with Excel. >> >> tbl2 <- addmargins(tbl1) >> write.csv(tbl2, "tt1.csv") >> >> As for the second question, the following does it. >> >> inx <- apply(tbl1, 1, function(x) all(x != 0)) >> tbl1b <- addmargins(tbl1[inx, ]) >> tbl1b >> >> >>...
2018 Feb 03
0
find unique and summerize
Hello, Thanks for the reproducible example. See if the following does what you want. IDNum <- sub("^(\\d+).*", "\\1", mydata$ID) Country <- sub("^\\d+(.*)", "\\1", mydata$ID) tbl1 <- table(Country, IDNum) addmargins(tbl1) tbl2 <- xtabs(Y ~ Country + IDNum, mydata) addmargins(tbl2) Hope this helps, Rui Barradas On 2/3/2018 3:00 AM, Val wrote: > Hi all, > > I have a data set need to be summarized by unique ID (count and sum of a > variable) > A unique individual ID (country name Abbrevi...
2018 Feb 03
2
find unique and summerize
Hi all, I have a data set need to be summarized by unique ID (count and sum of a variable) A unique individual ID (country name Abbreviation followed by an integer numbers) may have observation in several countries. Then the ID was changed by adding the country code as a prefix and new ID was constructed or recorded like (country code, + the original unique ID Example original ID
2007 Oct 24
2
adding total row/column to table-command
Dear R, I am often adding a total rows or column (sum over all rows or columns) when using table(data$1,data$2)... I do this now by adding the rows/columns and rbind() or cbind()... But there must be a more efficient way.... Could someone please give me a hint? Thank you! With my best regards, Georg. ******************* Georg Ehret Johns Hopkins Baltimore [[alternative HTML version deleted]]
2009 May 31
1
Bug in gmodels CrossTable()?
Is the code below showing a bug in Crosstable()? My expectation was that the values produced by xtabs were rounded instead of truncated: library(gmodels) abc <- c("a", "a", "b", "b", "c", "c") def <- c("d", "e", "f", "f", "d", "e") wgt <- c(0.8, 0.6, 0.4, 0.5, 1.4, 1.3)
2007 Oct 02
2
Calculating proportions from a data frame rather than a table
When one has raw data it is easy to create a table of one variable against another and then calculate proportions For example a.nice.table<-table(a,b) prop.table(a.nice.table,1) However, I looked at several papers and created a data frame of the aggregate data. That means I acually created a table except it is a data frame. The first column lists the name of the first author and the year. I
2007 Sep 30
1
Append the sum of each row and column to a table matrix
Dear list, I have following table ee<-table(ID,Day) ee Day ID 2 3 4 5 6 7 9 10 14 16 35 5 0 0 3 1 0 0 5 0 0 36 0 0 0 0 0 0 0 1 0 0 43 13 15 15 0 0 13 13 15 13 15 46 0 1 0 0 0 0 0 0 0 0 58 0 0 0 0 0 0 4 4 0 0 and want to calculate the sum for each row and column and then append the sums to the table matrix.
2007 Oct 08
5
Specify plot size
Hello, I have another (possibly easy) question: How to specify the size of a plot? When I draw a plot, I can freely change the size of the window, which is nice for single plots to find the best height/width ratio, but as I need a lot of plots in my work, I want to look them all the same, so I need to specify the size in advance. Thanks for help, Christoph
2009 Nov 08
2
Counting non-empty levels of a factor
Hi everyone, I'm struggling with a little problem for a while, and I'm wondering if anyone could help... I have a dataset (from retailing industry) that indicates which brands are present in a panel of 500 stores, store , brand 1 , B1 1 , B2 1 , B3 2 , B1 2 , B3 3 , B2 3 , B3 3 , B4 I would like to know how many brands are present in each store, I tried: result <-
2015 May 04
0
Version 3.16-0 of Hmisc now on CRAN
Several updates have been made to the Hmisc package: Changes in version 3.16-0 (2015-04-25) * html.contents.data.frame: corrected html space character to add semicolon * ggplot.summaryP: added size of points according to denominators * colorFacet: new function * labelPlotmath: added chexpr argument (used by rms::ggplot.Predict) * rcsplineFunction: added
2015 May 04
0
Version 3.16-0 of Hmisc now on CRAN
Several updates have been made to the Hmisc package: Changes in version 3.16-0 (2015-04-25) * html.contents.data.frame: corrected html space character to add semicolon * ggplot.summaryP: added size of points according to denominators * colorFacet: new function * labelPlotmath: added chexpr argument (used by rms::ggplot.Predict) * rcsplineFunction: added
2009 Feb 27
1
cross tabulation: convert frequencies to percentages
Hello, might be rather easy for R pros, but I've been searching to the dead end to ... twsource.area <- table(twsource, area, useNA="ifany") gives me a nice cross tabulation of frequencies of two factors, but now I want to convert to pecentages of those absolute values. In addition I'd like an extra column and an extra row with absolute sums. I know, Excel or the
2004 Jun 03
3
printing tabular data nicely
Hi R-heplers, I would like to print various matrices, dataframes, tables, etc to files, preferably nicely formatted postscript for import into papers. Is there a way to do this? I know ?cat, ?writeLines, ?format, ?paste. But I am not sure of a good combination of these in order to get a nice looking table of information. Any ideas? I guess I want (almost) publication ready output, just