If 'just' is the object with the character strings, then your expression:
as.numeric(gsub("\\$ ", "", ("just")))
was trying to substitute for the "$" in the string 'just' and then convert
it to numeric and of course you get NA.
This is probably want you wanted. (notice no quotes around 'just')
Thanks I tried it with your values and it works, but when I try it with my
values, plugging in "just" (not sure if i'm doing it right):
> as.numeric(gsub("\\$", "", ("just")))
This is what I get:
[1] NA
Warning message:
NAs introduced by coercion
Btw here are the values im wokring with u
Check this post:
https://stat.ethz.ch/pipermail/r-help/2010-February/227520.html
On Thu, Feb 11, 2010 at 2:39 PM, Mark Breman 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;cl
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="char
Read them in as character and then convert them:
> x <- c('4,123.45', '1,234,567.89')
> x
[1] "4,123.45" "1,234,567.89"
> as.numeric(gsub(',', '', x))
[1]4123.45 1234567.89
>
On Thu, Feb 11, 2010 at 2:39 PM, Mark Breman wrote:
> Hello,
>
> Is there an easy way to read a csv file with nu
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,
6 matches
Mail list logo