Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in R Programming by (50.2k points)

Say, for instance, I have the following dataset (txt/csv file) separated by commas and spaces:

5.006,84.698  

4.604,87.725  7.250,88.392  

6.668,91.556  

5.927,95.440  

4.953,99.695  7.387,100.489  

6.466,104.447  

5.599,107.548  

4.053,111.411  7.440,112.892  

6.096,116.417  

4.805,119.031  7.546,120.671  

6.149,123.793  

4.307,127.201  7.461,129.974  

5.493,132.853  7.641,135.393  

and I want it to be:

72 5.006  84.698    NA      NA  

73 4.604  87.725 7.250  88.392  

74 6.668  91.556    NA      NA  

75 5.927  95.440    NA      NA  

76 4.953  99.695 7.387 100.489  

77 6.466 104.447    NA      NA  

78 5.599 107.548    NA      NA  

79 4.053 111.411 7.440 112.892  

80 6.096 116.417    NA      NA   

81 4.805 119.031 7.546 120.671  

82 6.149 123.793    NA      NA  

83 4.307 127.201 7.461 129.974  

84 5.493 132.853 7.641 135.393  

Do you know the feasible way to read it that way in R?

1 Answer

0 votes
by (108k points)

For achieving that you have to first open the file in any text editor (notepad or something similar) and make the separators common on the whole file. You can either substitute ',' with spaces or vice-versa using Find and Replace all and then save the file.

Once you finish that, you can now use read.csv() with this new separator in R programming.

a <- read.csv("C:/Users/User/Desktop/file.csv", sep= " ", header=FALSE, fill = TRUE)

Browse Categories

...