1. Put the data in the Action box
The greatest use of the R language is to process data, or else learn it and speak so much, now is the subject.
#把数据放到操作框中
salary<-c (18700000,14626720,15426545,54659532,5445442101)
position<-c ("QB", "DE", "QB", "QA", "QB")
team<-c ("Colts", "patriots", "Panthers", "Bengals", "Giants")
name.last<-c ("Manning", " Brady "," Pepper "," Palmer "," Manning ")
name.first<-c (" Peyton "," Tom "," Julius "," Carson "," Eli ")
Top.5.salaries<-data.frame (name.last,name.first,team,position,salary)
top.5.salaries
Output:
Name.last Name.first Team position salary
1 Manning Peyton Colts QB 18700000
2 Brady Tom Patriots DE 14626720
3 Pepper Julius Panthers QB 15426545
4 Palmer Carson Bengals QA 54659532
5 Manning Eli giants QB 5445442101
2. Graphical interface Operation
Top.5.salaries<-edit (top.5.salaries)
When you do this, a graphical interface appears.
When you finish editing, close, the information you have changed has been saved. For example, I modified the last row of the position column QBC->QB
> top.5.salaries
name.last name.first team position salary
1 Manning Peyton Colts QB 18700000
2 Brady Tom Patriots DE 14626720
3 Pepper Julius Panthers QB 15426545
4 Palmer Carson Bengals QA 54659532
5 Manning Eli giants QB 5445442101
The modification was successful. The following statement will also bring up the graphical interface
Fix (Top.5.salaries)
3. Save the packet to a local
The Save method saves the packet to a local
Save (top.5.salaries,file= "D:/r/product/0119/top.5.salaries.rdata")
After execution, a file is generated in the directory
Use the command to read the Rgui again.
Load ("D:/r/product/0119/top.5.salaries.rdata")
4. Read external files
Create a new Top.5.salaries.csv file with the following contents:
Ame.last,name.firts,team,position,salary
"Manning", "Peyton", "Colts", "QB", 18700000
"Brady", "Tom", " Patriots "," QB ", 1245624
" Pepper "," Julius "," Panthers "," DE ", 14137500
" Palmer "," Carson "," Bengals "," QB ", 13980000
"Manning", "Eli", "Giants", "QB", 12916666
Top.5.salaries<-read.table ("Top.5.salaries.csv", header=true,seq= ",", quote= "\" ")
Top.5.salaries
Output:
1 name.last,name.firts,team,position,salary
2 manning,peyton,colts,qb,18700000
3 brady,tom, patriots,qb,1245624
4 pepper,julius,panthers,de,14137500
5 palmer,carson,bengals,qb,13980000
6 manning,eli,giants,qb,12916666
You can also write data to a local file, using the Write.table function.
5. Data in the database
The best solution is to export the data in the database to a text file before importing it into R.
The study of R language is over for the time being, and later there will be further improvement.