cdas007 cdas007 -4 years ago 168
R Question

Unable to remove V1,V2 while reading a csv file in R

I am trying to read a CSV file as follows -

Sr_No,Location_Coordinates,Location,Hospital_Name
1,11.6357989,Near Dollygunj Junction,Chakraborty Multi Speciality Hospital
2,11.8311681,Medical Board Office,Inhs Dhanvantri
3,11.8311681,Near,Maricar Hospital
4,11.6498468,Lamba Line,Pillar Health Centre


With Sr_No, etc, ..... being all the headers - but when i am doing read.csv it comes back with the values as -

v1,v2,v3,v4
Sr_No,Location Coordinates,Location,Hospital Name
1,11.6357989,Near Dollygunj Junction,Chakraborty Multi Speciality Hospital
2,11.8311681,Medical Board Office,Inhs Dhanvantri
3,11.8311681,Near,Maricar Hospital
4,11.6498468,Lamba Line,Pillar Health Centre


How to get rid of all the elements 'v1,v2,v3,v4', because when i am trying to call the data frame after reading the csv file

s <- read.csv("../hospitaldata.csv",header = FALSE, check.names = TRUE)


if i try to do 's$' it shows me the option of V1,V2,...

i need it to be like s$Sr_No,....

Any help is appreciated.

i tried using skip=1 but it did not help. I am using MacOs.

Answer Source

You can try this line:

s <- read.csv("../hospitaldata.csv",header = TRUE, check.names = TRUE)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download