Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial/Basic Commands: Difference between revisions
No edit summary |
|||
Line 10: | Line 10: | ||
<ul> | <ul> | ||
<li>[[Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial |Overview]]</li> | <li>[[Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial |Overview]]</li> | ||
<li>[[Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial/Crash_Course | Crash Course]]</li> | |||
<li id="current">[[Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial/Basic Commands | Basic Commands]]</li> | <li id="current">[[Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial/Basic Commands | Basic Commands]]</li> | ||
<li>[[Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial/Practical |Practical 1]]</li> | <li>[[Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial/Practical |Practical 1]]</li> | ||
Line 19: | Line 20: | ||
==Useful Commands and Functions== | |||
== | {| class="wikitable" border="1" | ||
|+ Data entry and manipulation: (x can be any of several types; y and z are vectors) | |||
|- | |||
! Command | |||
! Meaning | |||
|- | |||
| x<-c(1, 2, 3, 4) | |||
| Create a vector of numbers | |||
|- | |||
| x | |||
| Prints contents of x | |||
|- | |||
| y[2:5] | |||
| Returns 2nd to 5th elements of vector y | |||
|- | |||
| y[-3] | |||
| Returns a vector of all elements in y except for the 3rd | |||
|- | |||
| y[y<10] | |||
| Sub-vector of all entries in y less than 10 | |||
|- | |||
| z[y<10] | |||
| Sub-vector of all entries in z for which the corresponding entries in y are less than 10 (x & y must be same length) | |||
|- | |||
| x<-list(y,z), x$y , x$z | |||
| Construct of list with two vectors in it , Returns vector y, Returns vector z | |||
|- | |||
| x<-data.frame(y,z), x$y, x$z | |||
| Construct of dataframe* with two vectors in it, Returns vector y, Returns vector z | |||
|- | |||
| x<-factor(y) | |||
| Converts numeric type y into a factor | |||
|- | |||
| is.factor(y) | |||
| Returns “TRUE” if y contains factors (numeric or symbolic) | |||
|- | |||
| is.numeric(y) | |||
| Returns “TRUE” if y contains numeric data | |||
|- | |||
| is.na(y) | |||
| Returns “TRUE” for each entry | |||
|} | |||
Lists the different attributes of an array or dataframe | |||
levels(x)=c("a", "b",…) Assign names to each factor value | |||
x<-read.table(file="inp.txt") Read a dataset from an ascii text file of data. Add | |||
“header=TRUE” if the file contains descriptive headers | |||
load("filename") Loads R data from filename | |||
save(x, "filename") Saves R object x into filename | |||
save.image("filename") Saves all current R objects into filename | |||
Revision as of 07:58, 5 October 2009
<html> <body> <!-- Start of StatCounter Code --> <script type="text/javascript"> var sc_project=3315864; var sc_invisible=0; var sc_partition=36; var sc_security="8bb2efcd"; </script>
<script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div class="statcounter"><a class="statcounter" href="http://www.statcounter.com/"><img class="statcounter" src="http://c37.statcounter.com/3315864/0/8bb2efcd/0/" alt="blog stats" /></a></div></noscript> <!-- End of StatCounter Code -->
</body> </html>
Introduction to 'R'
Useful Commands and Functions
Command | Meaning |
---|---|
x<-c(1, 2, 3, 4) | Create a vector of numbers |
x | Prints contents of x |
y[2:5] | Returns 2nd to 5th elements of vector y |
y[-3] | Returns a vector of all elements in y except for the 3rd |
y[y<10] | Sub-vector of all entries in y less than 10 |
z[y<10] | Sub-vector of all entries in z for which the corresponding entries in y are less than 10 (x & y must be same length) |
x<-list(y,z), x$y , x$z | Construct of list with two vectors in it , Returns vector y, Returns vector z |
x<-data.frame(y,z), x$y, x$z | Construct of dataframe* with two vectors in it, Returns vector y, Returns vector z |
x<-factor(y) | Converts numeric type y into a factor |
is.factor(y) | Returns “TRUE” if y contains factors (numeric or symbolic) |
is.numeric(y) | Returns “TRUE” if y contains numeric data |
is.na(y) | Returns “TRUE” for each entry |
Lists the different attributes of an array or dataframe
levels(x)=c("a", "b",…) Assign names to each factor value x<-read.table(file="inp.txt") Read a dataset from an ascii text file of data. Add “header=TRUE” if the file contains descriptive headers load("filename") Loads R data from filename save(x, "filename") Saves R object x into filename save.image("filename") Saves all current R objects into filename