Site icon R-bloggers

R – Tutorial I

[This article was first published on R – StudyTrails, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

NOTE : This tutorial has been superseded by the exhaustive R tutorials Here

Basics

Vectors

b=c(“!”,2,a) = “!” “2” “1” “2” “3” and b=c(2,a) = 2 1 2 3.

> a
first second  third
1      2      3

> a=c(1,2,3)
> b=c(4,5)
> a+b
[1] 5 7 7
Warning message:
In a + b : longer object length is not a multiple of shorter object length

>  paste(c(“X”,”Y”), 1:10,2:5)
[1] “X 1 2”  “Y 2 3”  “X 3 4”  “Y 4 5”  “X 5 2”  “Y 6 3”  “X 7 4”  “Y 8 5”  “X 9 2”  “Y 10 3”

> a=c(1,2,3,4,5,6,7,8,9,10)
> b=c(TRUE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE)
> a[b]
[1]  1  4  5  6  8 10
> b=c(1:5)
> a[b]
[1] 1 2 3 4 5
> b=-(1:5)
> a[b]
[1]  6  7  8  9 10

To leave a comment for the author, please follow the link and comment on their blog: R – StudyTrails.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.