R Data Frame
A data frame can be understood as what we often call a "table."\\n\\nA data frame is a data structure in R, a special kind of two-dimensional list.\\n\\nEach column in a data frame has a unique column name, all columns have equal length, the data type within a column must be consistent, and different columns can have different data types.\\n\\n!(https://static.jyshare.com/images/mix/data-frame.svg)\\n\\nIn R, data frames are created using the `data.frame()` function. The syntax is as follows:\\n\\ndata.frame(β¦, row.names = NULL, check.rows = FALSE, check.names = TRUE, fix.empty.names = TRUE, stringsAsFactors = default.stringsAsFactors())\\n* **β¦**: Column vectors, which can be of any type (character, numeric, logical). They are generally specified in the form `tag = value`, or just `value`.\\n* **row.names**: Row names, defaulting to `NULL`. Can be set to a single number, a string, or a vector of strings and numbers.\\n* **check.rows**: Checks if row names and lengths are consistent.\\n* **check.names**: Checks if the variable names in the data frame are syntactically valid.\\n* **fix.empty.names**: Determines whether to automatically name unnamed arguments.\\n* **stringsAsFactors**: A logical value indicating whether character vectors should be converted to factors. The default in a fresh R session is `TRUE`, which can be changed by setting the option (`stringsAsFactors = FALSE`).\\n\\nThe following creates a simple data frame containing name, employee number, and monthly salary:\\n\\n## Example\\n\\ntable=data.frame(\\n\\n Name =c("Zhang San", "Li Si"),\\n\\n Employee ID =c("001","002"),\\n\\n MonthSalary =c(1000, 2000)\\n\\n)\\n\\nprint(table)# View table data\\n\\nExecuting the above code produces the following output:\\n\\nName Employee ID MonthSalary1 Zhang San 001 10002 Li Si 002 2000\\nThe structure of a data frame can be displayed using the `str()` function:\\n\\n## Example\\n\\ntable=data.frame(\\n\\n Name =c("Zhang San", "Li Si"),\\n\\n Employee ID =c("001","002"),\\n\\n MonthSalary =c(1000, 2000)\\n\\n)\\n\\n# Get data structure\\n\\nstr(table)\\n\\nExecuting the above code produces the following output:\\n\\n'data.frame': 2 obs. of 3 variables: $ Name: chr "Zhang San" "Li Si" $ Employee ID: chr "001" "002" $ MonthSalary: num 1000 2000\\nThe `summary()` function can display summary information for the data frame:\\n\\n## Example\\n\\ntable=data.frame(\\n\\n Name =c("Zhang San", "Li Si"),\\n\\n Employee ID =c("001","002"),\\n\\n MonthSalary =c(1000, 2000)\\n\\n)\\n\\n# Display summary\\n\\nprint(summary(table))\\n\\nExecuting the above code produces the following output:\\n\\nName Employee ID MonthSalary Length:2 Length:2 Min. :1000 Class :character Class :character 1st Qu.:1250 Mode :character Mode :character Median :1500 Mean :1500 3rd Qu.:1750 Max. :2000 \\nWe can also extract specific columns:\\n\\n## Example\\n\\ntable=data.frame(\\n\\n Name =c("Zhang San", "Li Si"),\\n\\n Employee ID =c("001","002"),\\n\\n MonthSalary =c(1000, 2000)\\n\\n)\\n\\n# Extract specified columns\\n\\n result <-data.frame(table$Name,table$MonthSalary)\\n\\nprint(result)\\n\\nExecuting the above code produces the following output:\\n\\ntable.Name table.MonthSalary1 Zhang San 10002 Li Si 2000\\nThe following form displays the first two rows:\\n\\n## Example\\n\\ntable=data.frame(\\n\\n Name =c("Zhang San", "Li Si","Wang Wu"),\\n\\n Employee ID =c("001","002","003"),\\n\\n Month
YouTip