What are vectors in R?

Quick Overview

Asks what a vector is in R and how it behaves. Tests the atomic types, coercion when types are mixed, vectorized operations and recycling, indexing, and how atomic vectors differ from lists.

What are vectors in R?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What are vectors in R? Explain what a vector holds, how you create one, and how R behaves when you combine or operate on vectors of different types or lengths. ```hint Type and length rules Consider what R has to do when one vector receives values of different types, and when an arithmetic operation gets two vectors of different lengths. ``` ### What a Strong Answer Covers - The definition: a one-dimensional, ordered collection, with single values as length-1 vectors - The atomic types and how `c()` coerces mixed types - Vectorized operations and recycling, including when R warns - Basic indexing - How atomic vectors relate to lists ### Follow-up Questions - What does `c(1, "a", TRUE)` return, and why? - What does `1:6 + 1:4` return, and what message does R print? - Why does `is.vector()` return `FALSE` for a factor? - Why is `seq_along(x)` safer than `1:length(x)` in a loop?

Overview: Asks what a vector is in R and how it behaves. Tests the atomic types, coercion when types are mixed, vectorized operations and recycling, indexing, and how atomic vectors differ from lists.

PracHub logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What are vectors in R?

Explain what a vector holds, how you create one, and how R behaves when you combine or operate on vectors of different types or lengths.

What a Strong Answer Covers Guidance

  • The definition: a one-dimensional, ordered collection, with single values as length-1 vectors
  • The atomic types and how c() coerces mixed types
  • Vectorized operations and recycling, including when R warns
  • Basic indexing
  • How atomic vectors relate to lists

Follow-up Questions Guidance

  • What does c(1, "a", TRUE) return, and why?
  • What does 1:6 + 1:4 return, and what message does R print?
  • Why does is.vector() return FALSE for a factor?
  • Why is seq_along(x) safer than 1:length(x) in a loop?