Opening and importing data in R is highly versatile, supporting various file formats such as RData, CSV, Excel, JSON, XML, and SQL databases. You can also datasets created in other programs like SAS or Stata. Make sure to have this dataset in your directory to import it correctly.
Example
Using CASchools data, we can import a CSV file using read.csv()
function. If this was an Excel file, we could use read_excel()
from readxl
package.
If we print my_data
, it looks something like this:
If you have collected data and need to begin manually inputting it into RStudio, we can use code to create a new dataset. Below is some example code on how to create a new data as a dataframe.
In the code above we are creating new data.frame
called example_dataset
. We specify the variables wages
, education
, age
, sex
, and language
.
Output of this example dataset looks something like this: