CSV (comma-separated values) Data
The comma-separated values (comma delimited, csv) format data are often used to share data among different software since almost all statistical software can read and output this type of data. A comma-separated values (CSV) file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. Such files often have an extension name "csv". An example csv file is available on our website with the following contents:
v1,v2 1,6 2,7 3,8 4,9 5,10
Read Data from a .csv File
The R function read.csv() function to read the csv data. The use of the function is similar to read.table(). By default, it assumes there are variable names in the data set. If no variable name is available, one should set header=FALSE
> csvdata<-read.csv("https://advstats.psychstat.org/data/csvdata.csv") > csvdata v1 v2 1 1 6 2 2 7 3 3 8 4 4 9 5 5 10 >
Save other types of data to csv format
Excel data
You can convert an Excel worksheet to a csv file by using the Save As command. Click the File tab, and then click Save As. In the Save as type box, choose the text file format as CSV (Comma delimited).
SPSS data
In File Menu, choose, "Save As...", in the drop down menu in the dialog box that opens choose "Save as type: 'Comma delimited (*.csv)')", and underneath that select "Save value labels where defined instead of data values" (or hit "Alt-a") and choose "Save".
SAS data
The simplest method to save the SAS data to the csv is to use the DEXPORT statement. Below is an example assuming sasdata is the SAS data. After submitting the code, SAS will create a csv file specified.
dm "dexport sasdata 'pathtocsvfile\new.csv' ";
Stata data
To convert a Stata data to Excel, use the "outsheet" command as shown below. The command will create a comma-delimited file called "new.csv".
outsheet using new.csv,c
To cite the book, use:
Zhang, Z. & Wang, L. (2017-2026). Advanced statistics using R. Granger, IN: ISDSA Press. https://doi.org/10.35566/advstats. ISBN: 978-1-946728-01-2.
To take the full advantage of the book such as running analysis within your web browser, please subscribe.
