Data Types in R

For understanding data types in any language, it often helps to find out the most elementary data type because often other data types are built on elementary ones. In our case, vectors are the most elementary so let’s define a vector first.

  • Vectors - They are used to store ordinal data (data where order matters) of the same base type ie. you can store 1 and 3.4 in a vector because they have the same base type - numeric. There are other types like logical (TRUE, FALSE), and character (“a”b"). If thats very confusing think about coordinates in a plane or space. The order of numbers used to specify coordinates matters( ie. (2,1) is different from (1,2) ) and hence we would use a vector to store things like that.
  • Arrays(multi-dimensional) - Arrays are the most common data types in other languages but not in R. R stores arrays as vectors with two other parameters - number of dimensions and names for those dimensions. 
  • Matrices - Matrices are like arrays in R but restricted to two dimensions where all columns need to be of the same type(or mode in R lingo). Remember matrices are used for complex computations like multiplication and determinant. So we need them to be of same type.
  • Data Frames - Data frames are like matrices but they allow for the columns to be of different types. They are meant to store data like we store it in tables. Data frames internally are stored as a list of vectors of the same length.
  • Lists - They are like vectors but allow you to store objects of other types (R has other different types of objects, including the ones we discussed here)

Comments

Popular posts from this blog

Why computers aren't amazingly smart

Making Machines : Introduction

Data Mining and R/Rattle : First Experiment