官术网_书友最值得收藏!

Data frames

Data frames are special lists that can also store tabular values. However, there is a constraint on the length of elements in the lists: they all have to be of a similar length. You can consider every element in the list as columns, and their lengths can be considered as rows.

Just like lists, a data frame can have objects belonging to different classes in a column; this was not allowed in matrices.

Let's quickly create a data frame using the data.frame() function:

a <- c(1, 3, 5)
b <- c("red", "yellow", "blue")
c <- c(TRUE, FALSE, TRUE)
df <- data.frame(a, b, c)
df
## a b c
## 1 red TRUE
## 3 yellow FALSE
## 5 blue TRUE

You can see the headers of a table as a, b, and c; they are the column names. Every line of the table represents a row, starting with the name of each row.

主站蜘蛛池模板: 闸北区| 两当县| 积石山| 石棉县| 景宁| 长宁县| 丹巴县| 沽源县| 甘泉县| 宜川县| 米泉市| 栾城县| 平阳县| 沁阳市| 雅安市| 九龙县| 德安县| 安阳县| 德令哈市| 平泉县| 马鞍山市| 绥化市| 聂拉木县| 汉中市| 鄂州市| 江安县| 渑池县| 信丰县| 双鸭山市| 崇仁县| 蒙城县| 仪征市| 胶南市| 湟源县| 凤山市| 松原市| 吴旗县| 林州市| 新郑市| 张家港市| 岳阳县|