Data Structures in R

Most functions and graphs will require information in a data frame structure. However, this differs by package so conversions might be necessary.

1) Data Frame

df <- data.frame(id = letters[1:10], x = 1:10, y = 11:20)

class(df) # "data.frame"


2) Matrix

matrix <- matrix(nrow = 2, ncol = 2)


class(matrix) # "matrix" "array"

3) Lists

list <- list(1, "a", TRUE, 1+4i)


class(list) # "list"

is.list(list) # TRUE

Data Structure Conversions

Convert Dataframe to Matrix

df.matrix <- as.matrix(data.frame)

class(df.matrix) # "matrix" "array"

Convert Matrix to Dataframe

matrix.df <- data.frame(matrix)

class(matrix.df) # "data.frame"

Convert Dataframe to List

Convert List to Dataframe

Convert Matrix to List

Convert List to Matrix


Sabalico Logo
Sabalytics Logo
Senty Logo
SEO Guide Logo
World Map Logo
rStatistics Logo
Day Map Logo
Time Zone Logo
Galaxy View Logo
Periodic Table Logo
My Location Logo
Weather Track Logo
Sprite Sheet Logo
Barcode Generator Logo
Test Speed Logo
Website Tools Logo
Image Tools Logo
Color Tools Logo
Text Tools Logo
Finance Tools Logo
File Tools Logo
Data Tools Logo
History of Humanity - History Archive Logo
History of Humanity - History Mysteries Logo
History of Humanity - Ancient Mesopotamia Logo
History of Humanity - Persian Empire Logo
History of Humanity - Alexander the Great Logo
History of Humanity - Roman History Logo
History of Humanity - Punic Wars Logo
History of Humanity - Golden Age of Piracy Logo
History of Humanity - Revolutionary War Logo