R Program to lists in r programming containing strings, vectors etc.

How to create a list containing strings, numbers, vectors, and logical values

Here we are explaining how to write an R program to create a list containing strings, numbers, vectors, and logical values. Here we are using a built-in function list() for this. This function helps to construct, coerce and check for both kinds of R lists. The syntax of this function is 

list(…) #Where … indicates objects, possibly named.

How to create a list containing strings, numbers, vectors, and logical values in the R program

Below are the steps used in the R program to create a list containing strings, numbers, vectors, and logical values. In this R program, we directly give the values to a built-in function list(). Here we are using variable Ldata for holding the list elements. Call the function list() for creating the list of different type values.

ALGORITHM

STEP 1: Assign variables Ldata with a list of values

STEP 2: Call the function list as list() with different type values

STEP 3: print the variable Ldata which holding different lists

R Source Code

                                          Ldata = list("Java", "PHP", c(2, 4, 6, 8), TRUE, 20.19, 62.54)
print("Data of the list:")
print(Ldata)
                                      

OUTPUT

[1] "Data of the list:"
[[1]]
[1] "Java"

[[2]]
[1] "PHP"

[[3]]
[1]  2  4  6 8

[[4]]
[1] TRUE

[[5]]
[1] 20.19

[[6]]
[1]62.54