-1

Here is the sample dataset. Here the problem is the seperator is :: but inbetween the movie name there is : so I am getting problem with this. Please help me out.

enter image description here

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
naveen
  • 1
  • 3
  • 2
    Do not post your data as an image, please learn how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) – Jaap Sep 28 '16 at 14:08

2 Answers2

0
Scanner scan = new Scanner(file);
while (scan.hasNextLine()) {
    String[] a = scan.nextLine().replace("\\t", ",").split(",");
    //do something with the array
}
scan.close();

This did:

  • create a scanner to process the file (Scanner scan)
  • scan in the next file line (scan.nextLine()) for each file line based on hasNextLine()
  • replaced tabs with commas (.replace("\t", ",")), so the separators were all the same
  • split into an array by commas. Now you can process all the data alike regardless of the length of each line.
  • Don't forget to close the scanner when you're done.

Thanks!

Meghshyam Sonar
  • 377
  • 4
  • 12
  • can you please look at the image which i kept.the data looks like that. i need a solution in R programming – naveen Sep 28 '16 at 10:45
0

You could try to do the following:

require(data.table)
input <- data.table(do.call(rbind,strsplit(readLines('file.txt'),'::' )))
input[, c("V3", "V4", "V5") := tstrsplit(V3, split = "|", fixed = T)]

The first line reads your file ("file.txt" should be substituted with your file name) using the :: as a separator. The second line splits the 1 column that contains all the classifications into 3 separate columns.