Submitted by : Manoj Pawar
Programming Tutorials: R Programming
Posted on : 2019-09-06

Data outside of R environment can be read in R.We can read and write data into various file formats like csv,excel,xml etc.Csv file is comma separated values which is in text format. We can create csv file using windows notepad and save as .csv extension. Consider input file is book2.csv.  

> y<-read.csv("book2.csv")

> print(y)

  id    name      eye_color         X

1  1    a          red              m

2  2    b          blue             f

3  3    c          blue             f

4  4    d          red              f

5  5    e          blue             m

6  6    f          brown            m

Given table contain 6 rows and 4 columns, when we want to find how many color, name and gender present in the table then we have to follow following command.

> table(y$color)

  blue   brown    red

    3     1     2

> table(y$name)

    a b c d e f

    1 1 1 1 1 1

> table(y$sex)

    f m

    3 3

 

Following output will show how many color present in the table by using graphical representation.

  

> barplot(table(y$eye_color),xlab = "color",ylab = "frequency",main = "title")

where,

xlab:shows name on x-axis.

ylab:shows name on y-axis.

main:shows title of chart.