Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Understanding Vectors | Section
Practice
Projects
Quizzes & Challenges
Quizer
Challenges
/
Essential R Programming for Absolute Beginners - 1768563985826

bookUnderstanding Vectors

Note
Definition

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:

12
vec <- c(1, 2, 3) vec
copy

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

1
c(2, TRUE, "some text")
copy
Oppgave

Swipe to start coding

Explore how R determines the data type of a vector when elements of different types are combined:

  1. Display the vector containing the elements 0, 10.5, and 20 (in that order).
  2. Display the vector containing the elements 1, 2.5, and 5 + 10i (in that order).
  3. Display the vector containing the elements 2.5, TRUE, and 5 (in that order).
  4. Display the vector containing the elements FALSE, 25.5, and 'R' (in that order).

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 15
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

close

bookUnderstanding Vectors

Sveip for å vise menyen

Note
Definition

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:

12
vec <- c(1, 2, 3) vec
copy

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

1
c(2, TRUE, "some text")
copy
Oppgave

Swipe to start coding

Explore how R determines the data type of a vector when elements of different types are combined:

  1. Display the vector containing the elements 0, 10.5, and 20 (in that order).
  2. Display the vector containing the elements 1, 2.5, and 5 + 10i (in that order).
  3. Display the vector containing the elements 2.5, TRUE, and 5 (in that order).
  4. Display the vector containing the elements FALSE, 25.5, and 'R' (in that order).

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 15
single

single

some-alt