WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

R · Basic · question 5 of 100

What are the basic data types in R? Provide examples.?

📕 Buy this interview preparation book: 100 R questions & answers — PDF + EPUB for $5

R has several basic data types, including numeric, character, logical, integer, complex, and raw.

Numeric: Numeric data types represent numbers, and can be either integers or real numbers. In R, numeric data types are represented by the numeric class. For example:

    # Creating a numeric variable
    x <- 3.14
    class(x) # numeric

Character: Character data types represent text, and are represented by the character class in R. Character strings are surrounded by either single or double quotes. For example:

    # Creating a character variable
    y <- "hello"
    class(y) # character

Logical: Logical data types represent boolean values (TRUE or FALSE), and are represented by the logical class in R. For example:

    # Creating a logical variable
    z <- TRUE
    class(z) # logical

Integer: Integer data types represent whole numbers, and are represented by the integer class in R. In contrast to numeric data types, integer data types cannot have decimal points. For example: r Copy code # Creating an integer variable a <- 5L class(a) # integer

Note that the L at the end of 5L indicates that a is an integer.

Complex: Complex data types represent complex numbers, and are represented by the complex class in R. Complex numbers have both a real and imaginary component. For example:

    # Creating a complex variable
    b <- 3 + 2i
    class(b) # complex

Raw: Raw data types represent raw bytes, and are represented by the raw class in R. Raw data can be used to represent binary data, such as images or sound files. For example:

    # Creating a raw variable
    c <- charToRaw("hello")
    class(c) # raw

In summary, R has several basic data types, including numeric, character, logical, integer, complex, and raw. These data types are represented by different classes in R, and each has its own specific uses and applications.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic R interview — then scores it.
📞 Practice R — free 15 min
📕 Buy this interview preparation book: 100 R questions & answers — PDF + EPUB for $5

All 100 R questions · All topics