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

Dataframes

A dataframe in R is a 2D object where the columns can contain data of different classes and types. This is very useful for practical data storage.

Dataframes can be created by using as.data.frame() on applicable objects or by column- or row-binding vectors using cbind.data.frame() or rbind.data.frame(). Here's an example where we can create a list of nested lists and turn it into a data frame:

list_for_df <- list(list(1:3), list(4:6), list(7:9))
example_df <- as.data.frame(list_for_df)

example_df will have three rows and three columns. We can set the column names just as we did with the matrix, though it isn't common practice in R to set the row names for most analyses. It can be demonstrated by the following code:

colnames(example_df) <- c("one", "two", "three")

We have covered a few of the key data structures in R in this section, and we have seen how to create and manipulate them. Let's try a few examples.

主站蜘蛛池模板: 缙云县| 社会| 西畴县| 腾冲县| 昭通市| 莱阳市| 司法| 本溪市| 江油市| 柏乡县| 揭西县| 天等县| 噶尔县| 浠水县| 阆中市| 三穗县| 北碚区| 钟祥市| 金溪县| 湘西| 甘泉县| 运城市| 丰都县| 土默特左旗| 东宁县| 中卫市| 仲巴县| 阿荣旗| 察隅县| 吴桥县| 台州市| 新龙县| 临漳县| 乐至县| 小金县| 潜山县| 长乐市| 商都县| 莱西市| 昌图县| 方城县|