R 3.31 data frame

  • The data frame is a table format data structure. The data frame is designed to model the data set, which is consistent with the concept of the data set in other statistical software such as SAS or SPSS.
  • A data set is usually a rectangular array of data, with rows representing observations and columns representing variables. Different industries have different names for the rows and columns of the data set.
  • The data frame is actually a list. The elements in the list are vectors. These vectors form the columns of the data frame. Each column must have the same length. All data frames are rectangular, and the columns of the data frame must be named.
  • The shape of the data frame is very similar to a matrix. In fact, it is a relatively regular list. Each column of the data frame must be of the same 2 types, and each row can be different.
  • The data frame is created by the data.frame function
  • Data frame access
    also uses [] for indexing. The index output includes row names and column names.
    Adding a "-" index means removing this part of the content. The name of the row and column can also be used to retrieve
    the name of the data.frame [," column Name"] Note that
    the name of data.frame with a comma ["row name",]
    can also be taken out
    with the $ symbol, eg, use the built-in data set women in R to access and draw the plot graph
women
plot(women$height,women$weight)

When using lm for linear regression, give the column name,
eg

lm(weight~height,data=women)

If you access multiple columns at a time, using the $ symbol to access is more troublesome.
After binding the data with attach, you can directly enter the column name in the command box without the $ symbol. After using the data box, use the detach function to unbind the data. The
same can be done with the with function. The result, without the $ sign, directly type the column name
eg

with(women,{height})

Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46445293/article/details/105218735