R语言读取外部数据
读取文本数据
#读取文本数据
getwd()
setwd("D:/data/Section_1")
csvdata<- read.csv("hs0.csv")
names(csvdata)
#或者使用read.table
tabledata <- read.table("hs0.csv",header = T,sep = ',' )
names(tabledata)
使用read.table读取数据时,如果第一行是变量名,必须指定header = T
If you are using the read.csv command, there is no need to write the header True and
separator as comma, but if you are using the read.table command, it is mandatory to use.
Otherwise, it will read the first variable from the dataset
输出结果
> names(csvdata)
[1] "X0" "X70" "X4" "X1" "X1.1" "general"
[7] "X57" "X52" "X41"