Understanding Vectors
A vector is a data structure that stores multiple values of the same type in a single variable.
Creating Vectors
To create a vector, use the c() function and separate values with commas:
12vec <- c(1, 2, 3) vec
Type Coercion in Vectors
Vectors must be homogeneous, so you cannot mix integers, logical values, and text in the same vector. If you include different data types in the same vector, R will convert all elements to a single common type.
Example
1c(2, TRUE, "some text")
Swipe to start coding
Explore how R determines the data type of a vector when elements of different types are combined:
- Display the vector containing the elements
0,10.5, and20(in that order). - Display the vector containing the elements
1,2.5, and5 + 10i(in that order). - Display the vector containing the elements
2.5,TRUE, and5(in that order). - Display the vector containing the elements
FALSE,25.5, and'R'(in that order).
Ratkaisu
Kiitos palautteestasi!
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Mahtavaa!
Completion arvosana parantunut arvoon 2.27
Understanding Vectors
Pyyhkäise näyttääksesi valikon
A vector is a data structure that stores multiple values of the same type in a single variable.
Creating Vectors
To create a vector, use the c() function and separate values with commas:
12vec <- c(1, 2, 3) vec
Type Coercion in Vectors
Vectors must be homogeneous, so you cannot mix integers, logical values, and text in the same vector. If you include different data types in the same vector, R will convert all elements to a single common type.
Example
1c(2, TRUE, "some text")
Swipe to start coding
Explore how R determines the data type of a vector when elements of different types are combined:
- Display the vector containing the elements
0,10.5, and20(in that order). - Display the vector containing the elements
1,2.5, and5 + 10i(in that order). - Display the vector containing the elements
2.5,TRUE, and5(in that order). - Display the vector containing the elements
FALSE,25.5, and'R'(in that order).
Ratkaisu
Kiitos palautteestasi!
single