简体   繁体   中英

R, how to read data from file and plot a histogram from them?

I'm new at R, and I have to write commands to read a file containing real values and then compute and plot a histogram of distributions, using 100 subintervals. I've been havin' some problems in using hist() function...

This is what I do for readin' data:

values = read.table("filepath.txt");

filepath.txt contains real values (2509.92, 615.41, 417.031, ... , 0.0516073, 0.023377, 0.00681471).

Then I've tried to follow these instructions ( http://msenux.redwoods.edu/math/R/hist.php ), but it did not work, because using method as.numeric() , the system thinks it's managin' integer data and all the values are set to 1.0

How could I do?

Thanks a lot!

If your "filepath.txt" is exactly as you show, it is a comma-separated file, and you need to specify such appropriately in your read.table call. That may be all you need to do.

The info on your referenced page has nothing to do with reading or converting data, so I'm not sure why you are asking about histogram generation when you know your source data is bad.

However, I'm not sure because your question is a little imprecise: there's no such thing as "the system." If you can provide the exact R code you are using to read the data file, and clarify whether "all values are set to 1.0" means the values in your variable values or all the data in the output of hist we can guide you further.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM