What are the different data structures in R?

devquora
devquora

Posted On: Feb 22, 2018

 

Data structure is a form of organizing and storing data. It is imperative to have a strong understanding of various data types and data structures in order to make the best use of R languages. R programming supports five types of data structures namely vector, matrix, list, data frame and factor.

  • Vector– This data structure contains an integer, double, complex, etc. It is a sequence of same data elements and c() function is used to create a vector in R programming.
  • Matrix- it is a two-dimensional data structure and is used to bind vectors from the same length. All the elements in the matrix have to be of the same type and it is created using a matrix() function. The value of row can be defined using nrow and the value of the column can be defined using ncol.
  • List- list includes data of different types like numbers, strings, vectors, etc. It is somewhat like a vector but it contains mixed elements. A list is created using ().
  • Data frame- it is a special list where each element is of the same length. A data frame has the features of both, matrices and lists. It is more generic than the matrix as different columns have different data types. It is crated using frame() function.
  • Factors-it is created using factor() function and is used to store predefined and categorical data.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    R Programming Interview Questions

    What is R Programming?

    R is a programming language and a software environment meant for statistical analysis and creating graphs. It is used b..

    R Programming Interview Questions

    Enlist some of the functions that R provides?

    The functions that R provides areMean- it is calculated by taking the sum of the values and dividing it by a number o..

    R Programming Interview Questions

    What are the steps involved in building and evaluating a linear regression model in R?

    The following steps are followed to build and evaluate a linear regression model in RThe first step is to divide the ..