1. Read from the clipboard
(1) Select the data block that needs to be calculated and copy it:
(2) Use the read.table() function in the compiler:
data = read.table("clipboard",header=T)
head(data)
In this way, the data copied in the clipboard is successfully read.
2. Read from a text file
Still use the read.table() function , just change "clipboard" to the file path and file name.
Among them, the safest and most common text data is the csv format , and the read.csv() function can be used directly.
(1) Read in a text file
data_2 = read.table("./case2.txt",header = T)
data_2
(2) Save as csv file
write.csv(data_2,"./case2.csv")
data_2_new = read.csv("./case2.csv")
data_2_new
3. Read from Excel file
Note: To use Excel file reading in R language, you need to install the R language package openxlsx first
library(openxlsx)
data_3 = read.xlsx("mvstats5.xlsx","d2.1")
head(data_3)