<<< Click here to go back
#Suppose we have 3 vectors of same dimension
patient_id = c(1,2,NA)
patient_name = c("x", "y", "z")
age = c(20,30,40)
A list is collection of object where each element can be of different data type. We define list with List function. List elements( components) can be of any type - vector, matrix, etc.
Suppose we have 3 objects
# A character vector
a = c("Ask", "Analytics")
# A matrix
b = matrix(1:4, nrow = 2)
# A logical vector
c= c(TRUE,FALSE)
we can create a list of the above 3 vectors:
List_1 = list(a,b,c)
Now to call any element of the List, we can use [[ ]] with position index and to check the list of objects in a list we can use command names
#To call the 3rd element, we write
List_1[[3]]
#To check the objects in List_1
names(List_1)
Let's now create a data in R with Matrix form:
Another method to create a data in R is Data Frame :
patient_id = c(1,2,NA)
patient_name = c("x", "y", "z")
age = c(20,30,40)
Another methods to create similar data in R are cbind and rbind functions:
We need to understand one thing very clearly :
In the environment section, all the assignments are categorized into two parts
1. Values
2. Data
All the vectors which are always uni-dimensional , are classified as values.
Matrix and Data frame outputs, which can be uni as well as two dimensional are classified as data.
A Matrix can have only one type of data, either all numeric or all character, data frame can have a mix of both.
We are concluding this article covering basics of R with one more type of object called "List"
A list is collection of object where each element can be of different data type. We define list with List function. List elements( components) can be of any type - vector, matrix, etc.
Suppose we have 3 objects
# A character vector
a = c("Ask", "Analytics")
# A matrix
b = matrix(1:4, nrow = 2)
# A logical vector
c= c(TRUE,FALSE)
we can create a list of the above 3 vectors:
List_1 = list(a,b,c)
Now to call any element of the List, we can use [[ ]] with position index and to check the list of objects in a list we can use command names
#To call the 3rd element, we write
List_1[[3]]
#To check the objects in List_1
names(List_1)
Enjoy reading our other articles and stay tuned with us.
Kindly do provide your feedback in the 'Comments' Section and share as much as possible.
Kindly do provide your feedback in the 'Comments' Section and share as much as possible.
No comments:
Post a Comment
Do provide us your feedback, it would help us serve your better.