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

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.

主站蜘蛛池模板: 德兴市| 无棣县| 博罗县| 永安市| 科技| 深圳市| 永兴县| 云梦县| 吴江市| 大荔县| 开远市| 平定县| 监利县| 英吉沙县| 桃江县| 三河市| 仁怀市| 江川县| 沐川县| 曲麻莱县| 新巴尔虎左旗| 霍林郭勒市| 华坪县| 岳池县| 宁陕县| 杭锦旗| 昭苏县| 乐东| 靖安县| 衡南县| 林州市| 迁安市| 奇台县| 峨眉山市| 车险| 奉节县| 资溪县| 手游| 万安县| 辽中县| 托克逊县|