Thursday 25 June 2015

Read csv file in R

CSV stands for Comma separated values file. It allows data to be stored in tabular format. By using read.csv() function, you can read a csv file in R.

For example, employee.csv file contains following data.

id,firstName,lastName,Place
501,Hari krishna,Gurram,Bangalore
502,Sankalp,Dubey,Pune
503,Phalgun,Garimella,Hyderabad
504,Sandesh,Nair,Trivendram



> csvData <- read.csv("employee.csv")
> 
> csvData
   id    firstName  lastName      Place
1 501 Hari krishna    Gurram  Bangalore
2 502      Sankalp     Dubey       Pune
3 503      Phalgun Garimella  Hyderabad
4 504      Sandesh      Nair Trivendram
>
> csvData <- read.csv(file="employee.csv", header=TRUE, sep=",")
>
> csvData
   id    firstName  lastName      Place
1 501 Hari krishna    Gurram  Bangalore
2 502      Sankalp     Dubey       Pune
3 503      Phalgun Garimella  Hyderabad
4 504      Sandesh      Nair Trivendram
> 
> csvData <- read.csv(file="employee.csv", header=FALSE, sep=",")
>
> csvData
   V1           V2        V3         V4
1  id    firstName  lastName      Place
2 501 Hari krishna    Gurram  Bangalore
3 502      Sankalp     Dubey       Pune
4 503      Phalgun Garimella  Hyderabad
5 504      Sandesh      Nair Trivendram


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment