R sonlari
Sonlar
R’da uchta son turi mavjud:
numericintegercomplex
Son turidagi o‘zgaruvchilar ularga qiymat berilganda yaratiladi:
Misol
x <- 10.5 # numeric
y <- 10L # integer
z <- 1i # complex
Numeric (sonli tur)
numeric ma’lumot turi R’dagi eng keng tarqalgan tur bo‘lib, kasr qismi bor yoki yo‘q har qanday sonni o‘z ichiga oladi, masalan: 10.5, 55, 787:
Misol
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)
O‘zingiz sinab ko‘ring »
Integer (butun son)
Integer — kasr qismi bo‘lmagan sonli ma’lumotlar. U o‘nli kasr saqlashi kerak bo‘lgan o‘zgaruvchini hech qachon yaratmasligingizga amin bo‘lganingizda ishlatiladi. integer o‘zgaruvchisini yaratish uchun butun son qiymatidan keyin L harfini qo‘yishingiz kerak:
Misol
x <- 1000L
y <- 55L
# Print values of x and y
x
y
# Print the class name of x and y
class(x)
class(y)
O‘zingiz sinab ko‘ring »
Complex (kompleks son)
complex son mavhum qism sifatida "i" bilan yoziladi:
Misol
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)
O‘zingiz sinab ko‘ring »
Turni o‘zgartirish
Quyidagi funksiyalar yordamida bir turdan boshqasiga o‘tkazishingiz mumkin:
as.numeric()as.integer()as.complex()
Misol
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)
O‘zingiz sinab ko‘ring »
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
