,

How to read a CSV file in R | Lecture 4

How to read a CSV file in R

CSV is called as Comma Separated Value file which can be easily generated using any spreadsheet application like OpenOffice, LibreOffice, MS Office, etc... 

We can also create csv files using any text editor as well as given below. 

Create a csv file as per the format given below:

Name, Age, Science, Maths, Social
Kumar,14,57,67,78
Anand,24,98,97,90
Balakumar, 25,35,45,56

To read this file

> mydata=read.csv("users.csv");
> mydata

       name age science maths social
1     kumar  14      57    67     78
2     Anand  24      98    97     90
3 Balakumar  25      35    45     56

To create a new file,

df <- data.frame(name = c("Jon", "Bill", "Maria"), age = c(23, 41, 32), science=c(20,30,40), maths=c(56,67,78), social=c(98,76,65))
write.csv(df,"anewfile.csv", row.names = FALSE)

CSV file in R

0 comments:

Post a Comment