简体   繁体   中英

Read a CSV in R as a data.frame

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"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM