YouTip LogoYouTip

R Func List

# R list() Function - Create Lists [![Image 3: R Language Examples](#) R Language Examples](#) The R list() function is used to create lists, which is the most flexible data structure in R. Lists can contain elements of different types and lengths, making them ideal for organizing complex data. The list() function syntax is as follows: list(...) ## Example # Create a list containing multiple types student <-list( name ="Zhang San", age =25, scores =c(88, 92, 76), passed = TRUE ) print("Student Information List:") print(student) # Access list elements via $ or [] print(paste("Name:", student$name)) print(paste("Age:", student$age)) print(paste("Score:", toString(student$scores))) print(paste("First Subject:", student$scores)) # Access nested elements print(paste("List Length:", length(student))) print("List Name:") print(names(student)) Executing the above code outputs the result as follows: "Student Information List:" $name "Zhang San" $age 25 $scores 88 92 76 $passed TRUE "Name: Zhang San" "Age: 25" "First Subject: 88" "List Length: 4" "List Name:" "name" "age" "scores" "passed" [![Image 4: R Language Examples](#) R Language Examples](#)
← R Func LogR Func Levels β†’