How to convert CSV into array in R? Last Updated : 02 Jul, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we are going to see how to convert CSV into an array in R Programming Language. If we load this file into any environment like python, R language .etc, the data will be displayed in rows and columns format, let us convert CSV file into an array. Each and every column in the CSV will be converted into array of multiple dimensions. Method 1 : Using loop. Here we will use loop to convert all the columns in to the array. R setwd("C:/Users/KRISHNA KARTHIKEYA/Documents") df = read.csv("item.csv") lst1 = list() for(i in 1:ncol(df)) { lst1[[i]] <- df[ , i] } names(lst1) = colnames(df) arr = array(unlist(lst1), dim = c(5, 5, 3)) print(arr) Output: Explanation : In the first step we changed the directory using setwd() function to where the csv file is located.In the next step we have imported a CSV file into R environment using read.csv() function.Then created a empty list.Using for loop extracted every element by column wise and passed to list() function.Converted list to array using array() by passing list variable as parameter. In the array() function we have used unlist() function. The unlist() function is used to convert list to vector. So, the unlist() with list variable is passed to array().Finally, printed the array variable. Method 2: Extract every column into separate variable and pass to array() function. R setwd('C:/Users/KRISHNA KARTHIKEYA/Documents') df = read.csv('item.csv') a = df$id b = df$item c = df$quantity d = df$price e = df$bought f = df$forenoon g = df$afternoon arr = array(c(a, b, c, d, e, f, g), dim = c(5, 3 ,2)) print(arr) Output: Explanation : In the first step we changed the directory using setwd() function to where the csv file is located.In the next step we have imported a CSV file into R environment using read.csv() function.Using $ operator we have extracted every column into separate variable.Pass all the column variables to array( ) and give dimensions using dim attribute.Finally, printed the array variable. Comment More infoAdvertise with us Next Article How to create an array in R K krishnakarthikeyakhandrika Follow Improve Article Tags : R Language R-CSV Similar Reads Convert list to array in R A list can be converted to array in R by calling unlist( ) function with created list as parameter. Now pass the unlist() function into array() function as parameter, and use dim attribute for specifying number of rows, columns and matrices. unlist() converts list to vector.  Syntax : array( unlist 1 min read How to Convert XML to CSV in R? Converting data from XML to CSV format can be a handy skill, especially when you need to work with data in a more accessible format like CSV. Here, we'll discuss about the process of converting XML files to CSV using R programming language for data analysis.What is XML (eXtensible Markup Language)?X 4 min read How to create an array in R The array is the fundamental data structure in R used to store multiple elements of the same data type. In this article, we will explore two different approaches to creating an array in R Programming Language. Creating an array in RBelow are the approaches for creating an array in R. Using array() f 4 min read How to Convert a List to a Dataframe in R We have a list of values and if we want to Convert a List to a Dataframe within it, we can use a as.data.frame. it Convert a List to a Dataframe for each value. A DataFrame is a two-dimensional tabular data structure that can store different types of data. Various functions and packages, such as dat 4 min read Convert a given matrix to 1D array in R In this article, let's discuss how to convert a Matrix to a 1D array in R. Functions Usedmatrix() function in R is used to create a matrix Syntax: matrix(data,nrow,ncol,byrow,dimnames) Parameter: data-is the input vector which becomes the data elements of the matrixnrow-is the numbers of rows to be 2 min read How to Convert a CSV File to Microsoft Excel in R CSV refers to Comma-Separated Values. It holds plain text as a series of values (cells) separated by commas (, ) in a series of lines (rows). CSV file can actually open in a text editor and read it. On the other hand, Excel is used to display the data in horizontal and vertical rows. The data are u 2 min read Like