AnyCompiler

R Ka Taaruf

R ek dynamically typed, interpreted language hai jo statistics aur data analysis ke liye banayi gayi hai — general-purpose programming pehle nahi hai jis mein stats baad mein bolt ki gayi ho, balke iska ulta hai. Is mein koi compile step nahi hota: ek R script top se bottom tak run hota hai jaise hi aap ise execute karte hain, Python ya Ruby ki tarah.

Iski sab se distinctive feature ye hai: R mein true scalars nahi hote. Is site ki zyada tar languages mein, 5 ek value hai aur [5, 6, 7] ek alag kism ki cheez hai — ek collection. R mein, 5 already ek numeric vector hai, bas iski length 1 hai. Koi special "lone number" type nahi hota jo "numbers ki sequence" se alag baitha ho — har cheez ek vector hai, aur ek plain value sirf ek vector hai jisay aap ne abhi tak longer banane ki zahmat nahi ki. Yehi ek fact hai jiski wajah se R ka arithmetic, indexing, aur uske error messages bhi waise hi dikhte hain, aur ye course isay aage ki har lesson ke peeche ka organizing idea manta hai.

Ek jhalak

Ye hai ek real R program, jo waqai is page ke apne compiler par execute hua hai — koi mockup nahi. nums * 2 aur sum(nums) dono poore vector par ek sath operate karte hain, kahin bhi koi loop likhe baghair.

nums <- c(1, 2, 3, 4, 5)
cat("R in action:\n")
print(nums * 2)
cat("Sum:", sum(nums), "\n")
Output
R in action:
[1]  2  4  6  8 10
Sum: 15

c(1, 2, 3, 4, 5) paanch numbers ka ek vector banata hai, aur nums * 2 un sab ko ek single expression mein 2 se multiply kar deta hai — ye wo kism ka operation hai jisay is site ki zyada tar doosri languages mein ek explicit loop (ya map call) chahiye hota. sum(nums) poore vector ko ek number mein reduce kar deta hai, jo, jaisa aap ab jaante hain, waqai sirf length 1 ka ek vector hai. Aage: your first program — print, cat, aur comments, baghair kisi compile step aur baghair kisi main function ki zaroorat ke.

Practice exercise

c() istemal kar ke 2, 4, aur 6 wala ek vector banao jiska naam nums ho, phir nums * 10 print karo pure vector ko ek sath multiplied dekhne ke liye, baghair kisi loop ke.