Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read a CSV in R as a data.frame

Tags:

dataframe

r

csv

I am new to R and trying to read a csv. The documentation shows a function read.csv(). However, when I read the file and check the type of the variable it shows a list. Documentation shows it as a data.frame. Can someone explain why it happens that way?

My code so far:

mytable<-read.csv(InputFile,header=TRUE,stringsAsFactors=FALSE)
dim(mytable)
typeof(mytable)

Output:

dim(mytable)
[1] 500  20

typeof(mytable)
[1] "list"
like image 569
AMisra Avatar asked Nov 16 '14 19:11

AMisra


1 Answers

As it is explained in the answer https://stackoverflow.com/a/6258536/8900683. In R every "object" has a mode and a class. The former represents how an object is stored in memory (numeric, character, list and function) while the later represents its abstract type.

For example:

d <- data.frame(V1=c(1,2))
class(d)
# [1] "data.frame"
mode(d)
# [1] "list"
typeof(d)
# list
like image 84
Rene B. Avatar answered Sep 24 '22 21:09

Rene B.