YouTip LogoYouTip

R Func Dataframe

# R data.frame() Function - Create Data Frame [![Image 3: R Language Examples](#) R Language Examples](#) The R data.frame() function is used to create data frames, which is one of the most core data structures in R. A data frame is similar to a table, where each column can be a different type of data (numeric, character, logical, etc.), but each column must have the same length. The syntax format of the data.frame() function is as follows: data.frame(..., stringsAsFactors = default.stringsAsFactors()) **Parameter Description:** * **...** Column data, which can be vectors, lists, or matrices. * **stringsAsFactors** Whether to automatically convert strings to factors (default is FALSE starting from R 4.0). ## Example ```R # Create DataFrame df<-data.frame( ID =1:5, Name =c("Zhang San", "Li Si", "Wang Wu", "Zhao Liu", "Qian Qi"), Age =c(25, 30, 28, 35, 22), Score =c(88, 92, 76, 85, 90), stringsAsFactors = FALSE ) print("DataFrame Content:") print(df) # View Basic Properties print("Structure:") print(str(df)) print(paste("Number of Rows:", nrow(df), "Number of Columns:", ncol(df))) print("Column Names:") print(colnames(df)) Executing the above code outputs the following result: ```text "DataFrame Content:" ID Name Age Score1 1 Zhang San 25 882 2 Li Si 30 923 3 Wang Wu 28 764 4 Zhao Liu 35 855 5 Qian Qi 22 90 "Structure:"'data.frame':5 obs. of 4 variables: $ ID: int 1 2 3 4 5 $ Name: chr "Zhang San" "Li Si" "Wang Wu" "Zhao Liu" ... $ Age: num 25 30 28 35 22 $ Score: num 88 92 76 85 90 "Number of Rows: 5 Number of Columns: 4" "Column Names:" "ID" "Name" "Age" "Score" [![Image 4: R Language Examples](#) R Language Examples](#)
← R Func DifftimeR Func Cumsum β†’