How can R language read data files?
In the R language, you can use the functions read.table() or read.csv() to read data files.
- You can use the read.table() function if the data file is a text file separated by spaces, tabs, or other delimiters. For example:
data <- read.table("data.txt", header = TRUE)
The file path is “data.txt”, with header = TRUE indicating that the first row contains variable names.
- If the data file is a CSV file separated by commas, you can use the read.csv() function, which has similar syntax to read.table().
data <- read.csv("data.csv", header = TRUE)
The path for the CSV file is “data.csv”.
After the reading is completed, the data will be stored in the data variable. You can modify the file path and other parameters according to actual circumstances.