0

I am reading a csv file which has columns as below

    V6          V7
1   232.2       448.0
2     8.0       11.7
3   744.5       1,220.6
4    72.6       277.3
5   579.8       1,007.4
6    79.4       88.9
7    55.7       127.4
8   480.7       1,138.3
9   848.3       3,246.8
10 -477.7       5,084.2
11  958.2       3,954.2

The output of str(df)

$ V6 : num  232.2 8 744.5 72.6 579.8 ...
$ V7 : chr  "448.0" "11.7" "1,220.6" "277.3" ...

The way I read the file is

df = read.csv("data.csv", skip = 1, header = FALSE, as.is = TRUE)

I tried to change the type of V7 as

df$V7 = as.numeric(df$V7)

However, I get lot's of NAs due to coercion. Probably it is due to the ",". How do I fix this?

Sotos
  • 51,121
  • 6
  • 32
  • 66
chintan s
  • 6,170
  • 16
  • 53
  • 86

1 Answers1

2

a post-processing:

df$V7 = as.numeric(gsub(",", "", df$V7))