R入门——数据框
** 数据框 ** 1.许多数据集是以数据框的形式出现。 2.一个数据框就是将许多向量组合起来的一个对象,它是二维的,通常 其列表示变量, 其行表示观测 , 显示数据框时左侧会显示观测值的序号。 建立数据框的函数 若数据本身保存在一个文件中, 则通过读取该文件建立数据框 read.table() 可以读取txt文件 R无法读取excel直接保存文件,应该文件——导出——csv格式保存 read.csv() 先将数据另存为带逗号的数据(Comma Seperated values) read.delim() 先将数据另存为用tab作为分界符的数据 注:若数据集很大(如1,000,000观测x200变量),则可由ODBC联接由数据库读入. 导入外部数据示例 建立如下数据,保存在 C:\Users\我\Desktop\example.csv 中 (RGui可读取有中文的文件) !!需使用 / 注意!! header=T,导入数据第一行标题 data=read.csv(“C:/Users/我/Desktop/example.csv”,header=T) data y x 1 3 13 2 5 24 3 2 6 4 7 21 5 9 26 更快捷的打开方式! file.choose() data=read.csv(file.choose()) data y x 1 3 13 2 5 24 3