Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Vectors | Basic Data Types and Vectors
R Introduction: Part I
course content

Conteúdo do Curso

R Introduction: Part I

R Introduction: Part I

1. Basic Syntax and Operations
2. Basic Data Types and Vectors
3. Factors

bookVectors

It's time to explore how to store multiple values within a single variable, which can be efficiently done using vectors.

It's essential to understand that a vector must contain data of the same type; this means you cannot mix integers, complex numbers, and logical values in a single vector.

Creating a vector in R is straightforward: just list all the values separated by commas inside the c() function. Here's how you do it:

12
vec <- c(1, 2, 3) # Create a vector vec # Output its value
copy

When you input different data types within the c() function, R will default to one type for all elements. For instance, in a vector like c(1, 2, 'some text'), all numeric values will be converted to text. The reasoning is straightforward: if you attempt to construct a vector with varying types, R will select the one type to which all values can be converted.

Tarefa
test

Swipe to show code editor

Now, let's examine which types will be adopted when a vector consists of different data types.

  1. Display the vector containing the elements 0, 10.5, and 20, in that specific 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.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 5
toggle bottom row

bookVectors

It's time to explore how to store multiple values within a single variable, which can be efficiently done using vectors.

It's essential to understand that a vector must contain data of the same type; this means you cannot mix integers, complex numbers, and logical values in a single vector.

Creating a vector in R is straightforward: just list all the values separated by commas inside the c() function. Here's how you do it:

12
vec <- c(1, 2, 3) # Create a vector vec # Output its value
copy

When you input different data types within the c() function, R will default to one type for all elements. For instance, in a vector like c(1, 2, 'some text'), all numeric values will be converted to text. The reasoning is straightforward: if you attempt to construct a vector with varying types, R will select the one type to which all values can be converted.

Tarefa
test

Swipe to show code editor

Now, let's examine which types will be adopted when a vector consists of different data types.

  1. Display the vector containing the elements 0, 10.5, and 20, in that specific 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.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 5
toggle bottom row

bookVectors

It's time to explore how to store multiple values within a single variable, which can be efficiently done using vectors.

It's essential to understand that a vector must contain data of the same type; this means you cannot mix integers, complex numbers, and logical values in a single vector.

Creating a vector in R is straightforward: just list all the values separated by commas inside the c() function. Here's how you do it:

12
vec <- c(1, 2, 3) # Create a vector vec # Output its value
copy

When you input different data types within the c() function, R will default to one type for all elements. For instance, in a vector like c(1, 2, 'some text'), all numeric values will be converted to text. The reasoning is straightforward: if you attempt to construct a vector with varying types, R will select the one type to which all values can be converted.

Tarefa
test

Swipe to show code editor

Now, let's examine which types will be adopted when a vector consists of different data types.

  1. Display the vector containing the elements 0, 10.5, and 20, in that specific 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.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

It's time to explore how to store multiple values within a single variable, which can be efficiently done using vectors.

It's essential to understand that a vector must contain data of the same type; this means you cannot mix integers, complex numbers, and logical values in a single vector.

Creating a vector in R is straightforward: just list all the values separated by commas inside the c() function. Here's how you do it:

12
vec <- c(1, 2, 3) # Create a vector vec # Output its value
copy

When you input different data types within the c() function, R will default to one type for all elements. For instance, in a vector like c(1, 2, 'some text'), all numeric values will be converted to text. The reasoning is straightforward: if you attempt to construct a vector with varying types, R will select the one type to which all values can be converted.

Tarefa
test

Swipe to show code editor

Now, let's examine which types will be adopted when a vector consists of different data types.

  1. Display the vector containing the elements 0, 10.5, and 20, in that specific 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.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 2. Capítulo 5
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt