Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get R to read a column of numbers in exponential notation?

Tags:

r

statistics

I'm trying to use R for the first time to make a histogram. I have a file containing one column of 100,000 floating-point numbers ranging in size from 8.85543e-07 to 1.15469e-03. R apparently doesn't recognize them as floating-point numbers because of the 'e' notation. How can I get R to read them. Thanks!

like image 641
user2594096 Avatar asked Jul 18 '13 05:07

user2594096


2 Answers

R can read such numbers just fine; there must be another value in there that's causing the problem.

If you read in your data using read.table/read.csv/read.delim, you can always convert your data to numeric if it didn't import correctly.

x <- as.numeric(as.character(df$x))

where df is the name of your data frame, and x is the column that you want.

like image 67
Hong Ooi Avatar answered Nov 14 '22 20:11

Hong Ooi


Read the file like this:

file_as_data_frame <- read.table("file.txt", colClasses="numeric")
like image 43
Pedro Reis Avatar answered Nov 14 '22 20:11

Pedro Reis