Reference: "R language Combat"
1. Get Help
Help.start () |
Open the Help document home page |
Help ("foo") or? foo |
See Help for function foo (quotation marks can be omitted) |
Help.search ("foo") or?? Foo |
Search for local help documents with Foo as a keyword |
Example ("foo") |
Example of use of function foo (quotation marks can be omitted) |
Rsitesearch ("foo") |
Search online documents and mailing list archives with foo as keyword |
Apropos ("foo", mode= "function") |
List all available functions with Foo in the name |
Data () |
Lists all available sample datasets included in the currently loaded package |
Vignette () |
List all vignette documents available in the currently installed package |
Vignette ("foo") |
Displays the specified vignette document for theme Foo |
Help.start ()
Open Document Home http://127.0.0.1:27064/doc/html/index.html
Help ("foo") or? foo
Foo is an existing function in R that opens the description document of the function directly.
Data ()
Lists all available sample datasets in the loaded package, and the data listed here is as straightforward to use as the datasets listed in LS (), but the LS () method does not list these datasets.
2. Working space
GETWD () |
Displays the current working directory |
SETWD ("Mydirectory") |
Modify the current working directory to Mydirectory |
LS () |
List objects in the current workspace |
RM (ObjectList) |
Remove (delete) one or more objects |
Help (Options) |
Show description of available options |
Options () |
Show or set current options |
History (#) |
Show the most recently used # commands (default is 25) |
SaveHistory ("MyFile") |
Save the command history to file MyFile (the default value is. Rhistory) |
LoadHistory ("MyFile") |
Loads a command history file (the default value is. Rhistory) |
Save.image ("MyFile") |
Save the workspace to file MyFile (the default value is. RData) |
Save (ObjectList, file= "MyFile") |
Saves the specified object to a file |
Load ("MyFile") |
Reads a workspace into the current session (the default value is. RData) |
Q () |
Exit R. You will be asked if you want to save your workspace |
SETWD ("Mydirectory")
SETWD () only changes the working directory, and then opens R when the working directory is back to the previous default working directory.
RM ()
Use the RM () method to delete all object methods in the Working Environment RM (LIST=C (LS (all=true))).
3. Graphics output
PDF ("Filename.pdf") |
PDF file |
Win.metafile ("Filename.wmf") |
Windows Metafile |
PNG ("Filename.png") |
PBG file |
JPEG ("Filename.jpg") |
JPEG files |
BMP ("Filename.bmp") |
BMP file |
PostScript ("Filename.ps") |
PostScript file |
Save the plots area directly as a picture.
4. Manipulating objects
Length (object) |
Displays the number of elements/components in the object |
Dim (object) |
Display the dimensions of an object |
Str (object) |
Show the structure of an object |
Class (Object) |
Display the class or type of an object |
Mode (object) |
Show the mode of an object |
Names (object) |
Displays the names of the components in an object |
C (Object, Object,...) |
Merging objects into a vector |
Cbind (Object, object, ...) |
Merging objects by column |
Rbind (Object, object, ...) |
Merging objects by rows |
Object |
Output an Object |
Head (object) |
List the starting part of an object |
Tail (object) |
List the last part of an object |
LS () |
Displays the current list of objects |
Rm (Object, object, ...) |
Deletes one or more objects. |
NewObject <-Edit (object) |
Edit the object and save as NewObject |
Fix (object) |
Edit objects directly |
Object
Output an object that looks better with head () or tail () when the dataset is larger.
Head () and tail ()
The default data is 6 rows, and you can define the amount of data you view. Head (Object,n) and tail (object,n), n is the number you want to see.
Fix (object)
A similar view () looks at the data, Eidt () edits the object.
5.
Different industries have different names for the rows and columns of a dataset. Statisticians call them observations (observation) and variables
(variable), a database analyst calls it record and field, and researchers in the data Mining/machine learning disciplines call them examples (example) and attributes (attribute)
6. Attach (), detach (), with ()
Summary (Mtcars$mpg) plot (mtcars$mpg,mtcars$disp) plot (MTCARS$MPG,MTCARS$WT) #也可写作: Attach (Mtcars) plot (mpg, disp) Plot (mpg, WT) detach (Mtcars) #或者是: With (Mtcars,{summary (MPG,DISP,WT) plot (mpg,disp) plot (mpg, WT)})
The assignment in the WITH () function only takes effect inside the function, which is equivalent to a local variable. To assign a value other than the structure of the WITH () function, you can apply a special assignment symbol <<-instead of <-.
With (Mtcars,{nokeepstas <-summary (MPG) keepstats <<-Summary (MPG)}) nokeepstatskeepstats
7.
Read.table Row.names Properties
Data.frame also has row.names properties
You can define row.names directly when you create a dataset, similar to the Col.names property.
8.
Factor factor
The difference between a common factor and an ordered factor
Status <-c ("Poor", "improved", "excellent", "Poor") #无序status <-factor (status, ordered=f) status
#有序status <-factor (status, ordered=t) status
#自定义顺序status <-Factor (Status,ordered=true,levels=c ("Poor", "improved", "excellent") status
Have any questions proposed welcome, reproduced please indicate the source, thank you!
R Language Foundation Memo