[R] thousands separator in console output?
Hello, I'm beginning with R and I'm wondering if there's any way to display large values (e.g. 161651654167) using my system's thousands separator or scientific notation. Thanks! [[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.
Re: [R] thousands separator in console output?
On Nov 11, 2009, at 3:52 PM, Patricio Cuarón wrote: Hello, I'm beginning with R and I'm wondering if there's any way to display large values (e.g. 161651654167) using my system's thousands separator or scientific notation. Thanks! To get scientific notation as a default for given large values, see ? options and note 'scipen', which by default is 0. 161651654167 [1] 161651654167 options(scipen = -5) 161651654167 [1] 1.616517e+11 That is about the only way, by default, to adjust the output of numeric values, for which R uses ?print.default. You can play with the value of scipen to get the behavior you wish for some definition of 'large' numbers. If you want to format large numbers with commas as the thousand separator, that will not happen by default, but you can use format() to do this when outputting numbers as you may need in a function and/ or for pretty printing in tables, etc.: format(161651654167, big.mark = ,) [1] 161,651,654,167 Note that the result is a character vector and not numeric. See ?format and perhaps ?formatC for more information. HTH, Marc Schwartz __ 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] thousands separator
Dear useRs, I was wondering how to deal with data where thousands separator is a space or a comma? with google, I thought I found the answer but the thread ( http://tolstoy.newcastle.edu.au/R/help/06/04/25524.html) just focuses on decimal separator. Is there any function to numbers written like this in a csv file? Thanks in advance Christophe -- Christophe DUTANG Ph. D. student at ISFA [[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.
Re: [R] thousands separator
What I do is read the file in and then convert the various columns to numeric x - read.table(..., as.is=TRUE) col2cvt - c('V1', 'V3','V6') # columns for conversion for (i in col2cvt){ x[[i]] - as.numeric(gsub(,, , x[[i]])) } Replace ',' with ' ' for blanks. On Tue, Jul 21, 2009 at 3:34 PM, christophe dutangduta...@gmail.com wrote: Dear useRs, I was wondering how to deal with data where thousands separator is a space or a comma? with google, I thought I found the answer but the thread ( http://tolstoy.newcastle.edu.au/R/help/06/04/25524.html) just focuses on decimal separator. Is there any function to numbers written like this in a csv file? Thanks in advance Christophe -- Christophe DUTANG Ph. D. student at ISFA [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] thousands separator
thanks, I test it on the following example 27 076 552 440.95,230 400.04,1 27 176 285 276.98,170 240.22,1 27 276 040 780.57,640 053.22,1 27 376 072 983.53,800 300.1,1 27 476 552 531.87,411 770.68,1 27 576 552 919.09,130 010.21,1 27 676 285 254.43,460 020.70,1 27 776 072 840.44,220 071.16,1 27 876 032 704.00,540 121.14,1 setwd(~/Desktop) x - read.table(untitled, as.is=TRUE, sep=,) col2cvt - c('V1', 'V2','V3') for(i in col2cvt) { x[[i]] - as.numeric(gsub( ,,x[[i]])) } print(x,digits=22) it works fine! Christophe Le 21 juil. 09 à 21:47, jim holtman a écrit : What I do is read the file in and then convert the various columns to numeric x - read.table(..., as.is=TRUE) col2cvt - c('V1', 'V3','V6') # columns for conversion for (i in col2cvt){ x[[i]] - as.numeric(gsub(,, , x[[i]])) } Replace ',' with ' ' for blanks. On Tue, Jul 21, 2009 at 3:34 PM, christophe dutangduta...@gmail.com wrote: Dear useRs, I was wondering how to deal with data where thousands separator is a space or a comma? with google, I thought I found the answer but the thread ( http://tolstoy.newcastle.edu.au/R/help/06/04/25524.html) just focuses on decimal separator. Is there any function to numbers written like this in a csv file? Thanks in advance Christophe -- Christophe DUTANG Ph. D. student at ISFA [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? -- Christophe Dutang Ph.D. student at ISFA, Lyon, France website: http://dutangc.free.fr [[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.