Solution Review: Handling CSV file
In this review, we provide a detailed analysis of the solution to the problem.
We'll cover the following
Solution: Input/Output from File
main.r
data.csv
path <- "data.csv"csvData = read.csv(path)items <- csvData$Itemwrite.csv(items, "output/outData.csv")
Explanation
In the code snippet above, we first fetch the data of the .csv
file in csvData
.
The data fetched from
read.csv()
is directly in the format of a data frame. Therefore,csvData
is a data frame. Now, we can excess one of the columnsItem
using the syntax:
csvData$Item
We store this column in the variable items
and then write on file output/outData.csv
.