Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read in column vectors from a .csv file in R

Tags:

dataframe

r

csv

So I have data being processed in Python that I'm outputting as a .csv file. I would like R to be able to read the .csv file in such a way that it turns it into a dataframe in which some of the columns are actually vectors.

Is this even possible and how would I format a .csv so that this could happen? Thanks!

like image 832
Zeke Avatar asked Dec 25 '22 17:12

Zeke


1 Answers

First, vectors are simply a sequence of data elements. And data frames are lists of equal length vectors.

Hence, you can easily reference each column of a data frame as a vector.

df <- read.csv('C:\\Path\\To\\DataFile.csv')

v1 <- df[[1]]  # by column number
v2 <- df[["col1"]]  # by column name
v3 <- df$col1  # by column name
like image 148
Parfait Avatar answered Jan 05 '23 03:01

Parfait