Reading a CSV file in R
Download a CSV (comma-separated values) file Download a CSV (comma-separated values) file. Right click on it and choose properties.
Highlight the location, right click on it and copy
Turn the back slashes into forward slashes and add the filename (including its extension) and use it the read.csv method The second “argument” of the read.csv method says TRUE the data file includes headers as the first line. The third “argument” of the read.csv method says that the delimiter (thing separating the data elements) is a comma
The head method shows the first several rows of data.
Showing file extensions: Find the Control Panel
Switch from categories to Large or small icons
Choose File Explorer Options
Click on View tab and uncheck the Hide extensions setting. Click Apply.
The field names that came in from the CSV file were weird (the original file has parentheses), so I used the names method to rename them.
Plot the data with Volume on the x axis.
Resulting plot
Obtain a linear model for the data.frame
Summary of linear model in Console
Compare to Excel 1
Compare to Excel 2
Use abline to display the fit
Display the equation
If you have an Excel file and want a CSV, then click on File/ Save As
Click Browse. Use the Save As type drop-down to choose CSV
If the data is in the “working directory” – found by using getwd() – then the file name is enough
Another possible change is to use the field names in the axis labels
Take the heart rate data below (same as on Friday from the first week of class). Use Excel to convert it to a CSV format file. Read that data into R and make a plot with a linear fit with the equation displayed on the graph. Speed_in_kph Pulse_in_bpm 57 1.6 69 3.1 78 4 80 5 85 6 87 6.9 90 7.7 92 8.7 97 12.4 108 15.3 119