title: “Importing Data in R”
author: “adusu”
date: “October 7, 2015”
output: html_document
READ.TABLE() FUNCTION
-To load the content of a text file into R, the function read.table() may be used
-usage :Type read.table({file},skip=,header=,…)at the command line
-Example: For file “testdata” with the following data:
Filename:testdata1.txt
Date of Creation:Oct 7th
Purpose:To test loading data into R
Movie,LeadCharacter1,LeadCharacter2,Result(Prediction),Will Collect
Rudramadevi,Anushka,Allu Arjun, Average,75 to 85Cr!
BruceLee,Ramcharan,Rakul Preet,Hit,65 to 70Cr!
Akhil,Akill,Sayesha,Average,20 to 30 Cr!
step-1:
set the working directory to the file path
example:
getwd()
“C:/Users/user/Documents”
i have set my working directory as
“D:/Rprogram ming”
moviedata<-"testdata1.txt"
moviedata
## [1] "testdata1.txt"
myedata<-read.table(moviedata,sep=",",header=TRUE,skip=3)
myedata
## Movie Lead.Character1 Lead.Character2 Result Will.Collect
## 1 Rudramadevi Anushka Allu Arjun Above Average 75 to 85Cr!
## 2 BruceLee Ramcharan Rakul Preet Hit 65 to 70Cr!
## 3 Akhil Akill Sayesha Average 20 to 30 Cr!
myedata[5]
## Will.Collect
## 1 75 to 85Cr!
## 2 65 to 70Cr!
## 3 20 to 30 Cr!
myedata$Result
## [1] Above Average Hit Average
## Levels: Above Average Average Hit
myedata$Movie
## [1] Rudramadevi BruceLee Akhil
## Levels: Akhil BruceLee Rudramadevi