Reputation: 680
In R i want to read the csv file data.csv
. The 'character set' is 'Unicode (UTF-8)' The file should look like this
ss11 009
ts10 114
...
So we have dimension 2000 times 2.
In R I write this
read.csv(file=".../data.csv", header=TRUE, sep="\t", fileEncoding="UTF-8")
but when I type dim(data)
I get 2000 1
but I should have 2000 2
.
When I type head(data)
I get
ss11009
ts10114
...
How can I read the csv file so I get all data with the right dimension ?
Upvotes: 0
Views: 621
Reputation: 14902
require(data.table)
dt <- fread("data.csv", encoding = "UTF-8")
dt
# V1 V2
# 1: ss11 9
# 2: ts10 114
str(dt)
# Classes ‘data.table’ and 'data.frame': 2 obs. of 2 variables:
# $ V1: chr "ss11" "ts10"
# $ V2: int 9 114
# - attr(*, ".internal.selfref")=<externalptr>
Upvotes: 1