Reading and Inspecting Data
Before you can analyze or visualize data in R, you need to bring your data into your R environment. Most often, data comes in text-based formats like CSV (comma-separated values) files. Loading these files and inspecting their structure helps you understand what variables are available, their types, and whether any cleaning is needed before further analysis. This foundational step ensures you work with accurate, well-understood data throughout your project.
123456library(readr) # Load a CSV file into a tibble data <- read_csv("https://staging-content-media-cdn.codefinity.com/courses/dd47061a-6da5-4e45-add5-cea0af087f14/iris_data.csv", show_col_types=FALSE) print(as.data.frame(data))
The library(readr) line loads the readr package, which provides the read_csv() function for efficient CSV file reading. The function call read_csv("data/iris.csv") reads the file named "iris.csv" from the "data" folder. The result is stored in the variable data, which is a tibble — a modern, user-friendly version of a data frame. This tibble automatically detects column names and types, displaying a clean preview when printed. By inspecting the first few rows and column types, you can confirm the data loaded correctly and begin exploring further.
Be careful with file paths — if R cannot find your file, check that the path is correct relative to your current working directory. CSV files with non-UTF-8 encoding may cause errors or misread characters; specify the encoding if needed. Also, missing values in your CSV may appear as NA in R, but sometimes they are coded differently (like empty strings or specific text). Always inspect your data after import to catch these issues early.
Bedankt voor je feedback!
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Geweldig!
Completion tarief verbeterd naar 7.69
Reading and Inspecting Data
Veeg om het menu te tonen
Before you can analyze or visualize data in R, you need to bring your data into your R environment. Most often, data comes in text-based formats like CSV (comma-separated values) files. Loading these files and inspecting their structure helps you understand what variables are available, their types, and whether any cleaning is needed before further analysis. This foundational step ensures you work with accurate, well-understood data throughout your project.
123456library(readr) # Load a CSV file into a tibble data <- read_csv("https://staging-content-media-cdn.codefinity.com/courses/dd47061a-6da5-4e45-add5-cea0af087f14/iris_data.csv", show_col_types=FALSE) print(as.data.frame(data))
The library(readr) line loads the readr package, which provides the read_csv() function for efficient CSV file reading. The function call read_csv("data/iris.csv") reads the file named "iris.csv" from the "data" folder. The result is stored in the variable data, which is a tibble — a modern, user-friendly version of a data frame. This tibble automatically detects column names and types, displaying a clean preview when printed. By inspecting the first few rows and column types, you can confirm the data loaded correctly and begin exploring further.
Be careful with file paths — if R cannot find your file, check that the path is correct relative to your current working directory. CSV files with non-UTF-8 encoding may cause errors or misread characters; specify the encoding if needed. Also, missing values in your CSV may appear as NA in R, but sometimes they are coded differently (like empty strings or specific text). Always inspect your data after import to catch these issues early.
Bedankt voor je feedback!