Professional Documents
Culture Documents
Big Data - Lab 2
Big Data - Lab 2
Second Section
Agenda
1. Accessing Data Frames with logical And\OR
2. Control Statements
3. Functions
Data Frames
▪ A group or collection of Vectors
▪ Most of the time, when data is loaded, it will be organized in a data
frame
Example:
>DF <- data.frame (h=c(150,160), w=c(65,72))
>DF
h w
1 150 65
2 160 72
Data Frames
> x <- data.frame (var1 = sample(1:5), var2 = sample(6:10), var3 = sample(11:15))
>x
> x$var2[c(1,3)] = NA
>x
Data frames using Logical And/OR
> x[x$var1 <=3 & x$var3 >11 , ]
> x <- 0
> for (i in 1:20)
{ x <- x + i}
>x
[1] 210
While
▪ While (condition) { expr_1 }
> x <- 0
> While (x != 60) { x <- x + 1 }
>x
[1] 60
Function Definition
function.name <- function(arg1, arg2, ...)
{ computations on the arguments and some other code }
Answer
Pow <- function(x=1,y=1)
{ z=1; for(i in 1:y) z<-z*x; return(z);}
Thank You