R

> v <- c(1, 3, 5)
> v
[1] 1 3 5
> v[2]
[1] 3
> v[2] <- 10
> v
[1]  1 10  5
> length(v)
[1] 2
1] 2
> v <- seq(1, 10)
> v
 [1]  1  2  3  4  5  6  7  8  9 10
> v <- rep(1:5, times=3)
> v
 [1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
> x <- c(1, 3, 5)
> y <- c(2, 4, 6)
> x*2
[1]  2  6 10
> x + y
[1]  3  7 11
> x > y
[1] FALSE FALSE FALSE
> x %in% y
[1] FALSE FALSE FALSE
> union(x, y)
[1] 1 3 5 2 4 6
> intersect(x, y)
numeric(0)
> setdiff(x, y)
[1] 1 3 5
> setequal(x, y)
[1] FALSE
> x <- c("S", "M", "L", "M", "L")
> x
[1] "S" "M" "L" "M" "L"
> x.fc <- factor(x)
> x.fc
[1] S M L M L
Levels: L M S
> levels(x.fc)
[1] "L" "M" "S"
> x.or <- ordered(x, levels=c("S","M","L"))
> x.or
[1] S M L M L
Levels: S < M < L
> x <- matrix(1:6, nrow=3, ncol=2)
> x
     [,1] [,2]
[1,]    1    4
[2,]    2    5
[3,]    3    6
> 
> x <- matrix(1:6, nrow=3, ncol=2, byrow=TRUE)
> x
     [,1] [,2]
[1,]    1    2
[2,]    3    4
[3,]    5    6
> x <- rbind(c(1, 2), 3:4, 5:6)
> x
     [,1] [,2]
[1,]    1    2
[2,]    3    4
[3,]    5    6
> x <- cbind(c(1,2),3:4,5:6)
> x
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
> x + 1
     [,1] [,2] [,3]
[1,]    2    4    6
[2,]    3    5    7
> 1/ x
     [,1]      [,2]      [,3]
[1,]  1.0 0.3333333 0.2000000
[2,]  0.5 0.2500000 0.1666667
> dim(x)
[1] 2 3
> nrow(x)
[1] 2
> ncol(x)
[1] 3
> x
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
> x[, 1]
[1] 1 2
> x[2,]
[1] 2 4 6
> x[1, 2]
[1] 3
> x[1, 1:2]
[1] 1 3
> x[1, c(1,2)]
[1] 1 3
> x[1, 2] <- 10
> x
     [,1] [,2] [,3]
[1,]    1   10    5
[2,]    2    4    6
> edit(x)
     col1 col2 col3
[1,]    1   10    5
[2,]    2    4    6
> x2 <- edit(x)
> x
     [,1] [,2] [,3]
[1,]    1   10    5
[2,]    2    4    6
> x <- list(5:10, "abc", matrix(1:6, nrow=2, ncol=3))
> x
[[1]]
[1]  5  6  7  8  9 10

[[2]]
[1] "abc"

[[3]]
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

> x[1]
[[1]]
[1]  5  6  7  8  9 10

> x[[1]]
[1]  5  6  7  8  9 10
> x[[3]][1, 2]
[1] 3
x <- read.table("sales.txt", header=TRUE, sep=",", na.strings="*")
sum(x$sales), max(x$sales), mean(x$sales),median(x$sales),sd($sales)
mean(x$DISTANCE, na.rm=TRUE), summary(x$sales), summary(x), str(x)