Reputation: 3
As you can see I would like to read a csv-table into my data-pool. The table has multiple columns but when i simply try following code:
reviews <- read.table("Sz-Iraki2.csv", fileEncoding = "UTF-8")
i get the error: Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 1 did not have 22 elements
When i Add header=True i get the error: more columns than column names. Seems like a basic problem but i can´t find the answer :(strong text
but should look like this
Data looks like this
Upvotes: 0
Views: 952
Reputation: 1914
You have to define a separator otherwise R fail to read data properly. Suppose your data structure is the following:
structure(list(month = 2:5, titles_tmp = structure(c(1L, 1L,
1L, 1L), .Label = "some text", class = "factor"), info_tmp = structure(c(1L,
1L, 1L, 1L), .Label = "More text", class = "factor"), unlist.text = structure(c(1L,
1L, 1L, 1L), .Label = "http://somelink.com", class = "factor")), .Names = c("month",
"titles_tmp", "info_tmp", "unlist.text"), class = "data.frame", row.names = c(NA,
-4L))
That means you separate each columns with single tab. Meaning you need to use sep = " "
as a data separator. Provided your data file name is "df.csv" the following should import your data nicely:
df = read.csv("Sz-Iraki2.csv", sep= " ", fileEncoding = "UTF-8")
Upvotes: 1
Reputation: 116
I like to use:
require(readr)
read_csv("myData.csv")
Seems more appropriate, if your file type is csv.
Also comes with some useful options like defining 'coltype' on import.
Upvotes: 0