Avatto > DATA SCIENTIST > PRACTICE QUESTIONS > R for Data Analytics > R Programming Fundamentals

R for Data Analytics MCQ - R Programming Fundamentals

R Programming Fundamentals – Quick Revision Notes

  • R is a programming language and environment widely used for statistical computing, data analysis, and data science.
  • R is case-sensitive. For example, score, Score, and SCORE are treated as different names.
  • Comments in R begin with the # symbol. Comments are ignored when the code is executed.
  • Objects or variables can be assigned values using <-. The = operator can also perform assignment in many contexts, although <- is conventionally used in R code.
  • Object names should be meaningful. Names can contain letters, numbers, dots, and underscores, but normally cannot begin with a number.
  • Use class() to determine the class of an R object and typeof() to inspect its underlying type.
  • print() explicitly displays an object in the console. cat() is useful for combining and displaying text and values in a more compact form.
  • ls() lists objects in an environment, while rm() removes specified objects.
  • getwd() returns the current working directory. setwd() changes the working directory.
  • source() reads and executes R commands stored in a script file.
  • Arithmetic operators include +, -, *, /, and ^. The ^ operator performs exponentiation.
  • %% returns the remainder of a division, while %/% performs integer division.
  • Comparison operators include ==, !=, >, <, >=, and <=.
  • Logical operators include & for AND, | for OR, and ! for NOT.
  • && and || are short-circuit logical operators, generally used when evaluating a single condition.
  • %in% checks whether values occur in another set of values.
  • Conditional execution is performed using if, else if, and else.
  • switch() can be useful when one of several alternatives needs to be selected from a single expression.
  • A for loop is commonly used to iterate through a known sequence.
  • A while loop continues as long as its condition evaluates to TRUE.
  • A repeat loop continues indefinitely unless it is explicitly terminated.
  • break immediately exits a loop, while next skips the remainder of the current iteration and continues with the next one.
  • User-defined functions are created using the function keyword.
  • Function inputs are supplied through arguments. Default argument values can be specified when a function is defined.
  • return() can explicitly return a value from a function. If it is omitted, R normally returns the value of the function\\\'s last evaluated expression.
  • Packages extend the functionality available in R. install.packages() installs a package, while library() loads an installed package for use.
  • attach() can make components of an object directly accessible by name, while detach() removes an attached object from the search path.
  • help() opens documentation for a topic. The ? operator provides a shorthand, such as ?print.
  • help.search() searches the R documentation when the exact help-topic name is unknown.
  • args() displays the formal arguments of a function.
  • NaN means Not a Number and represents an undefined numeric result, such as 0/0.
  • Inf and -Inf represent positive and negative infinity respectively.
  • abs() returns the absolute value of a number.

Remember These Common Distinctions

  • = / <- → assignment, whereas == → comparison.
  • / → ordinary division, %/% → integer division, %% → remainder.
  • & → logical AND, | → logical OR, ! → logical NOT.
  • break → leave the loop; next → skip only the current iteration.
  • install.packages() → install a package; library() → load it.
  • getwd() → get the working directory; setwd() → change it.
  • print() → standard object output; cat() → convenient text/value output.
  • help() → open known documentation; help.search() → search documentation.
  • NaN → undefined numeric result; Inf → infinity.

Why Practice with Avatto?
High Quality MCQsExam-focused questions with accurate answers
Detailed ExplanationsStep-by-step explanations to enhance learning
Latest Exam PatternBased on updated syllabus and pattern
Performance AnalyticsTrack performance and improve weak areas
100% Free PracticePractice unlimited questions for free
Boost Your PreparationAttempt mock tests, previous year papers and topic-wise quizzes.Explore All Tests →