2

Have three variables labeled "User-ID", "ISBN", and "Book-Rating" in the one column, but prefer three.

Rows: 1,149,903

I read the post about converting one to two, but encountered an error on the first line of code.

First Line:

 User-ID <- df[seq(from = 1, to =nrow(df), by = 3), 1]

Error Message:

 Error in seq.default(from = 1, to = nrow(df), by = 3) : 
 'to' must be of length 1

I saved the .csv file as a data.frame using:

as.data.frame.matrix(BX.Book.Ratings)

Below shows screenshot. Please let me know if I can provide additional information.

Thank you

Screenshot

Community
  • 1
  • 1
Scott Davis
  • 983
  • 6
  • 22
  • 43
  • Please help us help you by providing us with a **reproducible** example (i.e. code and example data), see http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for details. – Paul Hiemstra Sep 19 '13 at 05:12
  • Try `read.table("BX-Book-Ratings.csv", sep=";")` – Scott Ritchie Sep 19 '13 at 05:15
  • I am going to guess that you are using `read.csv` to read in the data. Most of the parameters in that function are dummy variables in that they do not change the functionality. As @Manetheran suggested, use `read.table` instead. – Ricardo Saporta Sep 19 '13 at 05:31
  • Probably safer not to use variables with dashes in them, like `User-ID`. – beroe Sep 24 '13 at 01:10
  • @beroe thanks will keep that in mind. I downloaded this from a website as test data. link:https://www.informatik.uni-freiburg.de/~cziegler/BX/. Used the CSV dump link – Scott Davis Sep 25 '13 at 16:59

1 Answers1

6

This should work:

 read.table(text=BX.Book.Ratings$V1,sep=";",header=TRUE)
agstudy
  • 119,832
  • 17
  • 199
  • 261
  • 1
    @AnandaMahto -- Sadly, I didn't get out of bed until hours later, and SO's time tagging isn't that precise :-( . I'd assumed (yeah, bad me) from Saporta's comment that agstudy's answer didn't show up until later on. – Carl Witthoft Sep 19 '13 at 12:41
  • @CarlWitthoft, SO's time tagging is actually *very* precise--hover over the time values for the specific time :) I'm just provoking you--I doubt either user cares much about it much.... – A5C1D2H2I1M1N2O1R2T1 Sep 19 '13 at 12:45
  • @AnandaMahto Thanks for the hover-tip. I never knew that. And to agstudy: most certainly it was a weak joke. I need to use those tags. – Carl Witthoft Sep 19 '13 at 14:16
  • @agstudy Thank you for getting back. I put in read.table(text=BX.Book.Ratings$V1,sep=";",header=TRUE). I got the following error: Error in textConnection(text) : invalid 'text' argument – Scott Davis Sep 22 '13 at 22:41
  • @Manetheran I put in your command and got the following result. [ reached getOption("max.print") -- omitted 1038576 rows ] I am trying to find the command for viewing the table – Scott Davis Sep 22 '13 at 23:17
  • @Manetheran I made a mistake of not putting the file name. Here is the new command: BXBOOKRATINGS <- read.table("BX-Book-Ratings.csv", sep=";"). Viewed the data, but still has 1048576 obs. of 1 variables. My intention involves separating the data into three variables. Thanks again – Scott Davis Sep 22 '13 at 23:37