0

I got data (many columns), some containing numeric data, others are string. The numeric data is stored with a thousand separator, hence the data looks like:

col1; col2; col3; col4; col5
100410; "abc"; "def"; 100.277; 30.997
100411; "abc"; "def"; 130.277; 30.927

The following will read the data correctly, but with col4 and 5 as character type.

df <- read.table(pathToFile, stringsAsFactor=F, sep = ";")
str(df)

 $ col1  : int  100410 100410 ...
 $ col2  : chr  "abc" "abc"
 $ col3  : chr  "def" "def"
 $ col4  : chr  "100.277" "130.277"
 $ col5  : chr  "30.997" "30.927"

Now: how can I dynamically convert the character columns which do contain numeric data (col4 and col5), but keep the string columns the way they are (col2 and col3)?

Dendrobates
  • 3,294
  • 6
  • 37
  • 56

0 Answers0