आर नंबर


नंबर

R में तीन संख्या प्रकार होते हैं:

  • numeric
  • integer
  • complex

संख्या प्रकारों के वेरिएबल तब बनते हैं जब आप उन्हें एक मान निर्दिष्ट करते हैं:

उदाहरण

x <- 10.5   # numeric
y <- 10L    # integer
z <- 1i     # complex

संख्यात्मक

एक numericडेटा प्रकार R में सबसे सामान्य प्रकार है, और इसमें दशमलव के साथ या बिना कोई संख्या होती है, जैसे: 10.5, 55, 787:

उदाहरण

x <- 10.5
y <- 55

# Print values of x and y
x
y

# Print the class name of x and y
class(x)
class(y)

पूर्णांक

पूर्णांक दशमलव के बिना संख्यात्मक डेटा हैं। इसका उपयोग तब किया जाता है जब आप निश्चित होते हैं कि आप कभी भी ऐसा वेरिएबल नहीं बनाएंगे जिसमें दशमलव होना चाहिए। एक चर बनाने के लिए , आपको पूर्णांक मान के बाद integer अक्षर का उपयोग करना चाहिए :L

उदाहरण

x <- 1000L
y <- 55L

# Print values of x and y
x
y

# Print the class name of x and y
class(x)
class(y)

जटिल

एक complexसंख्या को " i" के साथ काल्पनिक भाग के रूप में लिखा जाता है:

उदाहरण

x <- 3+5i
y <- 5i

# Print values of x and y
x
y

# Print the class name of x and y
class(x)
class(y)

रूपांतरण टाइप करें

आप निम्नलिखित कार्यों के साथ एक प्रकार से दूसरे प्रकार में परिवर्तित कर सकते हैं:

  • as.numeric()
  • as.integer()
  • as.complex()

उदाहरण

x <- 1L # integer
y <- 2 # numeric

# convert from integer to numeric:
a <- as.numeric(x)

# convert from numeric to integer:
b <- as.integer(y)

# print values of x and y
x
y

# print the class name of a and b
class(a)
class(b)