Nicola Sturaro Sommacal (Quantide srl)
2010-Sep-28 11:48 UTC
[R] Table with different digit number
Hi! I have a table representing both absolute and relative frequency, for example (code to get example data under the signature): Italy Germany absolute 100 105 relative 40.51 41.18 How can I print a different number of decimal digits? I try to transform to as.character, but cells result aligned to left and I don't like this solution. At the end of my work I need to export the table to HTML, so this can be do also with xtable package. Thanks in advance for your help. Nicola Sturaro Sommacal -- Quantide srl http://www.quantide.com ________________________________________________________ This is the code to get the data.frame with the data above: df = data.frame(italy = c(100,40.51), germany = c(105, 41.18)) row.names(df) = c("absolute", "relative") [[alternative HTML version deleted]]
Try this: df[1,] <- as.character(df[1,]) On Tue, Sep 28, 2010 at 8:48 AM, Nicola Sturaro Sommacal (Quantide srl) < mailinglist@sturaro.net> wrote:> Hi! > > I have a table representing both absolute and relative frequency, for > example (code to get example data under the signature): > > Italy Germany > absolute 100 105 > relative 40.51 41.18 > > How can I print a different number of decimal digits? I try to transform to > as.character, but cells result aligned to left and I don't like this > solution. At the end of my work I need to export the table to HTML, so this > can be do also with xtable package. > > Thanks in advance for your help. > > Nicola Sturaro Sommacal > > -- > Quantide srl > http://www.quantide.com > > ________________________________________________________ > > This is the code to get the data.frame with the data above: > > df = data.frame(italy = c(100,40.51), germany = c(105, 41.18)) > row.names(df) = c("absolute", "relative") > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Try round(df,2) for two decimal digits Gabriela 2010/9/28, Nicola Sturaro Sommacal (Quantide srl) <mailinglist at sturaro.net>:> Hi! > > I have a table representing both absolute and relative frequency, for > example (code to get example data under the signature): > > Italy Germany > absolute 100 105 > relative 40.51 41.18 > > How can I print a different number of decimal digits? I try to transform to > as.character, but cells result aligned to left and I don't like this > solution. At the end of my work I need to export the table to HTML, so this > can be do also with xtable package. > > Thanks in advance for your help. > > Nicola Sturaro Sommacal > > -- > Quantide srl > http://www.quantide.com > > ________________________________________________________ > > This is the code to get the data.frame with the data above: > > df = data.frame(italy = c(100,40.51), germany = c(105, 41.18)) > row.names(df) = c("absolute", "relative") > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- _________________________ Lic. Mar?a Gabriela Cendoya Mag?ster en Biometr?a Profesor Adjunto Facultad de Ciencias Agrarias UNMdP - Argentina