YouTip LogoYouTip

R Func Str

# R str() Function - View Object Structure [![Image 3: R Language Examples](https://example.com/images/up.gif) R Language Examples](https://example.com/r/r-examples.html) The R str() function is used to quickly view the internal structure of R objects. str() is a powerful tool for exploring data structures, it can display the object type, number of elements, and content preview. The str() function syntax is as follows: str(object) **Parameter Description:** * **object** The R object to view. ## Examples # View vector structure x <-c(1, 2, 3, 4, 5) print("Vector structure:") str(x) # View data frame structure df<-data.frame( Name =c("Zhang San", "Li Si", "Wang Wu"), Age =c(25, 30, 28), Score =c(88.5, 92.0, 76.5), stringsAsFactors = FALSE ) print("Data frame structure:") str(df) # View list structure my_list <-list( name ="Zhang San", age =25, scores =c(88, 92, 76) ) print("List structure:") str(my_list) Executing the above code produces the following output: "Vector structure:" num [1:5] 1 2 3 4 5 "Data frame structure:"'data.frame':3 obs. of 3 variables: $ Name: chr "Zhang San" "Li Si" "Wang Wu" $ Age: num 25 30 28 $ Score: num 88.5 92 76.5 "List structure:"List of 3 $ name : chr "Zhang San" $ age : num 25 $ scores: num [1:3] 88 92 76 [![Image 4: R Language Examples](https://example.com/images/up.gif) R Language Examples](http://www.tutorial
← R Func SubsetR Func Sprintf β†’