Beginner R Introduction (3): R call for multivariate data: read data from clipboard, text file and Excel table

1. Read from the clipboard

(1) Select the data block that needs to be calculated and copy it:

Insert picture description here

(2) Use the read.table() function in the compiler:

data = read.table("clipboard",header=T)
head(data)

Insert picture description here
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

Insert picture description here

data_2 = read.table("./case2.txt",header = T)
data_2

Insert picture description here

(2) Save as csv file

write.csv(data_2,"./case2.csv")

Insert picture description here

data_2_new = read.csv("./case2.csv")
data_2_new

Insert picture description here

3. Read from Excel file

Note: To use Excel file reading in R language, you need to install the R language package openxlsx first
Insert picture description here

library(openxlsx)
data_3 = read.xlsx("mvstats5.xlsx","d2.1")
head(data_3)

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45154565/article/details/109848548