How could you read this dataset in R
, the problem is
that the numbers are floats and are like 4,000000059604644E+16
and they are separated by a ,
4,000000059604644E-16 , 7,999997138977056E-16, 9,000002145767216E-16
4,999999403953552E-16 , 6,99999988079071E-16 , 0,099999904632568E-16
9,999997615814208E-16 , 4,30000066757202E-16 , 3,630000114440918E-16
0,69999933242798E-16 , 0,099999904632568E-16, 55,657576767799999E-16
3,999999761581424E-16, 1,9900000095367432E-16, 0,199999809265136E-16
How would you load this kinf of dataset in R so it has 3 columns.
If I do
dataset <- read.csv("C:\\data.txt",header=T,row.names=NULL)
it would return 6 columns instead 3...
Thus, we might want to create data or perform calculations with comma as decimal separator. In R, we can do this by just using the code options(OutDec=","). Once we will type this in R console, all the numerical values with decimals will be printed with commas in place of dots.
If you don't get the number of columns you expect In many countries this is not an issue, but the Swedish standard is using a comma as decimal separator, while R uses a decimal point.
It might be best to transform that input data to use decimal points, rather than commas, in the floating point numbers. One way you could do this is to use sed (it looks like you are using Windows, so you would likely need to sed to use this approach):
sed 's/\([0-9]\),\([0-9]\)/\1.\2/g' data.txt > data2.txt
File data2
looks like this:
4.000000059604644E-16 , 7.999997138977056E-16, 9.000002145767216E-16
4.999999403953552E-16 , 6.99999988079071E-16 , 0.099999904632568E-16
9.999997615814208E-16 , 4.30000066757202E-16 , 3.630000114440918E-16
0.69999933242798E-16 , 0.099999904632568E-16, 55.657576767799999E-16
3.999999761581424E-16, 1.9900000095367432E-16, 0.199999809265136E-16
Then in R:
dataset <- read.csv("data2.txt",row.names=NULL)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With