R Programming, For Beginners, Quick Start Guide. by Yao Ray

R Programming, For Beginners, Quick Start Guide. by Yao Ray

Author:Yao, Ray [Yao, Ray]
Language: eng
Format: epub
Publisher: Step by Step Tutorial eBook & Book
Published: 2020-08-05T16:00:00+00:00


unlist( )

unlist( ) can convert a list to a vector.

Example 5.18

> myList <- list(2:6) # create a list

> print(myList)

Output:

[[1]]

[1] 2 3 4 5 6

> myVector <- unlist (myList) # conversion

> print(myVector)

Output

[1] 2 3 4 5 6

Explanation:

myVector <- unlist (myList) converts a list to a vector.

Summary

In R, a value is considered to be a vector; its length is 1.

The example to create one element vector:

> print("good") # “good” is a character vector

[1] "good"

The example to create a multiple element vector:

> print(2: 8)

[1] 2 3 4 5 6 7 8

> print(c(3,4,5))

[1] 3 4 5

seq(v1, v2, by = step) can create a vector from v1 to v2.

by = step specifies the distance among each element.

[index] can access all elements of a vector, the index starts with 1.

TRUE, FALSE, 1,0 , and all numbers can work as an index.

[-index] Assigning a negative value to an index can remove the corresponding element.

When two vectors of different lengths are manipulated, shorter vectors are treated as equal lengths.

“sort( vector, decreasing=TRUE/FALSE)” sorts elements in a vector.

list(val1, val2, val3, … ) can create a list.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.