Read and View
Before you can analyze data, you need to bring it into your R environment. In most real-world scenarios, data is stored in external files or databases. The first step in any data analysis workflow is importing that data so you can begin exploring and working with it.
Common data sources
Real-world data often comes from a variety of sources, such as:
- CSV (comma-separated values) files;
- Excel spreadsheets;
- Plain text (TXT) files;
- Databases (e.g., SQL, SQLite, PostgreSQL);
- Web APIs or other online sources.
R provides a range of functions and packages to help read data from each of these sources easily.
Reading a CSV file
CSV is one of the most commonly used formats for storing tabular data. To import a CSV file into R, we typically use a function that reads the file and stores it in a data frame - a structure that organizes data in rows and columns.
df <- read_csv("car_details.csv")
Viewing your data
Once the data is loaded, it's helpful to take a quick look at it. One simple way to do this in RStudio is with the View()
function:
View(df)
Takk for tilbakemeldingene dine!
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 4
Read and View
Sveip for å vise menyen
Before you can analyze data, you need to bring it into your R environment. In most real-world scenarios, data is stored in external files or databases. The first step in any data analysis workflow is importing that data so you can begin exploring and working with it.
Common data sources
Real-world data often comes from a variety of sources, such as:
- CSV (comma-separated values) files;
- Excel spreadsheets;
- Plain text (TXT) files;
- Databases (e.g., SQL, SQLite, PostgreSQL);
- Web APIs or other online sources.
R provides a range of functions and packages to help read data from each of these sources easily.
Reading a CSV file
CSV is one of the most commonly used formats for storing tabular data. To import a CSV file into R, we typically use a function that reads the file and stores it in a data frame - a structure that organizes data in rows and columns.
df <- read_csv("car_details.csv")
Viewing your data
Once the data is loaded, it's helpful to take a quick look at it. One simple way to do this in RStudio is with the View()
function:
View(df)
Takk for tilbakemeldingene dine!