# qualquer coisa escrita depois de # torna-se um comentario. Comentarios sao elementos que nao sao "vistos" pelo R ao rodar um codigo.

# Originalmente elaborado por Sacha Siani e David Franca em 05/07/2017. 


1+2+3

2+3*4

3/2+1

4*3**3

sqrt(2)

sin(3.14159)

sin(pi)

sqrt(tan(45*pi/180))

#### LOGICAL OPERATORS ####

1 == 2

1 != 2

1 <= 2

1 < 2

1 > 2

1 >= 2

T & T

T & F

T | T

T | F

((1==2)|(2>1))&(4>=sqrt(tan(45*pi/180)))

#### VARIABLES ####

x <- 5 #Atribui ? vari?vel x o valor 5

x #Mostra o valor de x. Procure ver as vari?veis daqui para baixo!

x = pi

sin(pi) -> x

y <- sqrt(5)

y+x

x <- 25

x * sqrt(x) -> x1

x2.1 = sin(x1)

x2.2 = cos(x1)

xsq = x2.1**2 + x2.2**2


#### VECTORS ####

x <- c(2,3,5,7,11)

y <- c(x,13,17,19)

xx <- 1:10

xx <- 100:1

seq(1,10,1)

seq(1,10,2)

seq(10,1,-3)

rep(1,10)

rep(c(1,2),10)

rep(4:1,1:4)

rep(c(23,32,42),c(3,1,2))

# string!

c = c("jan", "fev", "mar")

rep(c, times=9)

repetir <- rep(c, each= 10)

repetir



meses = month.name

meses

meses = rep(meses,2)

#### VECTOR OPERATIONS ####

x <- 1:10

x + 2

sqrt(x)

y <- 21:30

x + y

y <- c(1,2)

x + y 

length(x)

rev(x)

summary(x)

x**x

#### VECTOR INDEX ####
x <- 1:10


x[2] #Mostra a posi??o 2 do vetor x!

y <- x[c(1,2,3)]

x[4:7]

x[12]

x <- c(6,5,6,4,4,3,4,2,3,4)

y <- c(5,3,4,2,6,5,4,5,4,3)

xeq4 <- x == 4

y[xeq4]

x[-3]

x[-c(3,4,7)]

x[y] 

#### FUNCTIONS ####

seq(1,27,3) 

seq(from=1,to=27,by=3)

seq(from=1,to=27,length=4)

seq(f=1,t=27,l=4)

seq(t=27,l=4,f=1)

seq(1,4)

seq(1)

seq()

sqrt()

?seq #call for help!

#### MATRIX ####

x <- 1:12

xmat <- matrix(x,ncol=3)

matrix(x,ncol=3,byrow=T)

dim(xmat)

summary(xmat)

summary(as.numeric(xmat))

x1 <- matrix(1:6,ncol=2)

x2 <- matrix(6:1,ncol=3)

x1*x2 #same dimension!

x1%*%x2

t(x1)*x2


#### Statistics
sum(y)

mean(y)

var(y)

w1 <- c(y, NA)

w1

mean(w1)

mean(w1, na.rm= TRUE)

sqrt(var(y))

sd(y)

summary(y)


###LA?O####

for (i in 1:10){  print(i)}
