Friday, August 11, 2017

Julia - Language - DataArrays - Vectors and Matrices

The advantage of using DataArrays over standard Array type in Julia is that we can store values with "no value" (NA). Also, similar to standard array type in Julia we can create:

  • vectors
  • matrices

Vectors - One Dimensional Array:


To create a vector using standard array:

julia> array_1d = [1,2,3,4,5]
5-element Array{Int64,1}:
 1

 2
 3
 4
 5

To create a data vector using dataarray's:


julia> darray_1d = data([1,2,3,4,5])
5-element DataArrays.DataArray{Int64,1}:
 1
 2
 3
 4
 5


Matrix - Two Dimensional Array:

Creating a 2 dimensional matrix in standard Julia:

julia> matrix_2d = [1 2 3 ; 4 5 6]
2x3 Array{Int64,2}:
 1  2  3
 4  5  6

Creating a 2 dimensional matrix using Data Arrays.

julia> da_matrix_2d = data([1 2 3 ; 4 5 6])
2x3 DataArrays.DataArray{Int64,2}:
 1  2  3
 4  5  6


We see that the main advantage of using DataArrays in Julia over standard arrays is that we can use NA values ("no value", NULL, missing value) in DataArrays. But, dataarrays are having one main limitation - we cannot use it to store multiple datatypes in multiple columns. Basically, we cannot use it like an excel sheet.

Now, to overcome this limitation of dataarrays, julia recommends us to utilize the DataFrames package.

No comments:

Post a Comment