You are on page 1of 1

Crea on of List in R

Problem: Using the following informa on given create a list and assess the list for further calcula ons.

Numbers: 25,45,67,89,92,45,64

Logicals: True, False, True, True, False

Profit =238

Names: Arun, Varun Tharun

Aim: To create a list and access the elements from the list.

1. Crea on of list

Procedure:

Use func on list( if two or more values <variable name = c( values)> if single value is given variable
name=<value>)

Procedure:

mylist= list(Numbers=as.numeric(c(25,45,67,89,92,45,64)),logicals=as.logical(c(TRUE, FALSE, TRUE, TRUE,


FALSE)), Profit=as.numeric(238),Names=as.character(c("Arun", "Varun", "Tharun")))

Result: mylist is created as list with above elements.

mylist
$Numbers
[1] 25 45 67 89 92 45 64

$logicals
[1] TRUE FALSE TRUE TRUE FALSE

$Profit
[1] 238

$Names
[1] "Arun" "Varun" "Tharun"
2. To process values in Numbers under mylist

i) mean value of values in Numbers

Procedure :

Use func on mean(<listname>$<vector name>

mean(mylist$Numbers)

Result:

61

You might also like