0

I am not able to rearrange my data in R. I am using following code.

data_1=read.table(file="filename.csv",sep=",")

I am getting...

               Month     Open      High      Low        Close
April-2015     27954.86  29094.61  26897.54  27011.31    NA
May-2015       27204.63  28071.16  26423.99  27828.44    NA
June-2015      27770.79  27968.75  26307.07  27780.83    NA
July-2015      27823.65  28578.33  27416.39  28114.56    NA

But I want it as...

Month          Open      High      Low       Close
April-2015     27954.86  29094.61  26897.54  27011.31
May-2015       27204.63  28071.16  26423.99  27828.44
June-2015      27770.79  27968.75  26307.07  27780.83
July-2015      27823.65  28578.33  27416.39  28114.56

Can someone help me please.

Thank you so much.

Sanjeev Shinde
  • 63
  • 1
  • 3
  • 14

1 Answers1

0
# My input file abcde.csv looks like below:

,One,Two,Three
a,b,c
c,b,d
a,b,c

# What happend when you read the above file
data <- read.csv("abcde.csv",sep=",",header=TRUE)
data
  X One Two Three
1 a  b   c   NA
2 c  b   d   NA
3 a  b   c   NA

Remove the comma in the first line in your input file before column name Month, save it and then again read it in the same way. This time it would work.

# If you also do not want to display row names given by R, you can print like this
print (data, row.names=FALSE)
  One Two Three
  a    b   c   
  c    b   d   
  a    b   c   

Hope this sample helps.

Sowmya S. Manian
  • 3,723
  • 3
  • 18
  • 30