Gerrit Gerrit - 3 months ago 12
R Question

Importing csv data to data frame not working

I try to load data from a csv to a data frame. What I do is that:

input <- read.csv("CONCAT_RESULT.CSV", sep = ",", skip = 1, col.names = c("ABS_ERG","MEHRFACH_COUNTER","TECH_KEY","XX_KEY","YY_SCHLUESSEL","CCC","LAND","HIERARCHIE_STICHTAGSABZUG","DATUM_SST_ERZEUGUNG","UHRZEIT_SST_ERZEUGUNG","FRUEHESTES_ABZUGSDATUM","AGGR_KLASSE_ID","ANTWORT_NUM","ANTWORT_TEXT","UMFRAGETYP_ID","ZZZ_ID","TTT_ID","BEANTWORTUNG_TYP","TRANSFORMIERT"))


In the next step I remove a few columns:

input["HIERARCHIE_STICHTAGSABZUG"] <- NULL
input["DATUM_SST_ERZEUGUNG"] <- NULL
input["UHRZEIT_SST_ERZEUGUNG"] <- NULL
input["FRUEHESTES_ABZUGSDATUM"] <- NULL
input["ANTWORT_TEXT"] <- NULL


Then I try to convert it to a data.frame with:

input.data <- as.data.frame(input)


But
typeof(input.data)
returns:
[1] "list"


Can anybody tell me why?

Thanks

Answer

A data.frame is a list of vectors of the same length. Thus, list is a correct type for a data.frame.

Try

typeof(data.frame(a=1, b=2, c=3))

to see, that a data.frame is just a list. To learn more, see help(mode) and help(data.frame).

Comments