[R] read numeric values with thousands seperator from csv file
Ista Zahn
istazahn at gmail.com
Thu Feb 11 20:55:27 CET 2010
It's not particularly nice, but you could do
Dat <- read.table(textConnection('Date;opening;High;Low;closing;Volume
12/02/08;4,764.95;4,897.62;4,729.13;4,895.31;-
13/02/08;4,868.02;4,927.81;4,833.85;4,898.60;-
14/02/08;4,942.18;4,962.43;4,877.88;4,895.99;-'), sep=";",
header=TRUE, colClasses="character")
Dat$opening <- as.numeric(gsub(",", "", Dat$opening))
Dat$High <- as.numeric(gsub(",", "", Dat$High))
Dat$Low <- as.numeric(gsub(",", "", Dat$Low))
Dat$closing <- as.numeric(gsub(",", "", Dat$closing))
-Ista
On Thu, Feb 11, 2010 at 7:39 PM, Mark Breman <breman.mark at gmail.com> wrote:
> Hello,
>
> Is there an easy way to read a csv file with numeric values that contain
> thousands seperators. The file looks like this:
>
> Date;opening;High;Low;closing;Volume
> 12/02/08;4,764.95;4,897.62;4,729.13;4,895.31;-
> 13/02/08;4,868.02;4,927.81;4,833.85;4,898.60;-
> 14/02/08;4,942.18;4,962.43;4,877.88;4,895.99;-
>
> I want to get the numeric values as..., well, numeric values, and not as
> character strings.
>
> I tried read.csv() with the colClasses parameter but that does not help and
> it looks like read.csv() does not support the big.mark="," parameter.
>
> Thanks,
>
> -Mark-
>
> [[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.
>
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
More information about the R-help
mailing list