#1

f.obs<- function(variable){

      A<-sort(variable)

      B<-A

      Final<-cbind(c(B[1],B[3:10],B[2]),c(B[11],B[13:21],B[12]))

      Final

      } 

      [,1]  [,2]

[1,] "f1"  "m1"

[2,] "f2"  "m2"

[3,] "f3"  "m3"

[4,] "f4"  "m4"

[5,] "f5"  "m5"

[6,] "f6"  "m6"

[7,] "f7"  "m7"

[8,] "f8"  "m8"

[9,] "f9"  "m9"

[10,] "f10" NA  

[11,] "f1"  "m10" 

#2 

a)

      table(ragged[,1]) 
 

b)  A<-as.numeric(row.names(ragged))

      X<-ragged[,order(A)]

      X

c) 

#3 

reduce<- function(x,operator){

      if(operator=="+")

            Ans<-sum(c(x))

      if(operator=="*")

            Ans<-prod(c(x))

      if(operator=="&")

            Ans<-all(c(x))

      if(operator=="|")

            Ans<-any(c(x)) 

      Ans

      } 

accumulate<-function(x,operator){

      Ans<-NULL

      for(i in 1:length(x)){

            Ans<-c(Ans,reduce(x[1:i],operator))

            }

      Ans

      }