← Back to R Course | Chapter 3: Vectors | Lesson 1 of 7

Vectors बनाना

एक vector values की एक line है जो same kind की साथ store हैं, एक string पर same-colored beads की एक row की तरह। यह R में सबसे basic container है।

In this page:

  1. Vectors बनाना
Syntax
r
vector_name <- c(value1, value2, value3)
vector_name <- 1:10
vector_name <- seq(from, to, by = step)

Vectors बनाना

एक vector R की सबसे fundamental data structure है -- values का एक ordered collection जो सब same type share करते हैं। x <- 5 जैसी एक single value भी technically length 1 का एक vector है।

Vectors वह building block हैं जिनसे R की दूसरी data structures, जैसे matrices और data frames, built हैं।

Note: R में लगभग सब कुछ एक vector है, scalars भी -- कोई separate single-value type नहीं है।

उदाहरण: Creating Vectors

markup
x <- 5
y <- c(1, 2, 3, 4, 5)

cat(length(x), length(y), "\n")
print(y)
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. c के बिना y <- (1, 2, 3) लिखना, जो एक syntax error है।
  2. यह उम्मीद करना कि x <- 5 जैसी एक single value एक vector से अलग होगी, जब R में यह length 1 का एक vector है।
  3. c(1, "a") जैसे types mix करना और यह देखकर surprised होना कि सारे elements characters बन जाते हैं।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.