I'm trying to read a file which uses :: as the column seperator:
userID::MovieID::Rating::Timestamp
1::1193::5::978300760
1::661::3::978302109
1::914::3::978301968
1::3408::4::978300275
Here is my code
tr = read.table("/home/user/ml-1m/ratings.dat",sep = ":" )
print(tr)
the result is :
V1 V2 V3 V4 V5 V6 V7
1 2 NA 318 NA 5 NA 978298413
2 2 NA 1207 NA 4 NA 978298478
3 2 NA 1968 NA 2 NA 978298881
4 2 NA 3678 NA 3 NA 978299250
5 2 NA 1244 NA 3 NA 978299143
6 2 NA 356 NA 5 NA 978299686
7 2 NA 1245 NA 2 NA 978299200
I don't want the NA value.
But if I set sep="::" ,there is error invalid 'sep' value: must be one byte
How can I fixed this?
The text file importing functions only support single characters as column separators. However, you can tell read.table to ignore columns for import with its colClasses parameter (see the help file):
read.table(text = "userID::MovieID::Rating::Timestamp
1::1193::5::978300760
1::661::3::978302109
1::914::3::978301968
1::3408::4::978300275",
sep = ":", colClasses = c(NA, "NULL"),
header = TRUE)
# userID MovieID Rating Timestamp
#1 1 1193 5 978300760
#2 1 661 3 978302109
#3 1 914 3 978301968
#4 1 3408 4 978300275
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With