#Christine Woods.  1704446. ACCA5021
#Statistical Programming Data Manipulation in R

n<-12                                                            #Vector for the first positive integer
x<-NULL                                                          #Empty vector to place variable

for(i in seq(n)){                                                #creating the loop for the sequence 
  
  if (n[i]%%2==0){                                               #first loop to check for even number
    n<-c(n,n[i]/2)                                               #if statement for if the number is even (half of the prervious variable)
 print(n)             
  } 
  else                                                           #2nd loop if the vairable is an odd number
    n<-c(n,(n[i]*3)+1)                                           #calculation if the variable is an odd number
}


Fibonacci<-numeric(12)                                            #Looking for the first 20 fibonacci numbers
Fibonacci[1]<-Fibonacci[2]<-1                                      
for (i in 3:20)Fibonacci[i]<-Fibonacci[i-2]+Fibonacci[i-1]        #Loop to add each number to the previous number for repeated concatenation 
print("First 20 Fibonacci number;")                               #by repeated addition - prints out the first 20 numbers
print(Fibonacci)                                                  #results show 12 in NOT a fibonacci number


n<-12                                                             # renaming the vector to calculate the square root of 12
sqrt(n)                                                           #Square root of n is 3.46 therefor is not an integer square root as it has 
                                                                  #remainder numbers

column_name<-c("N","Terms","Fibonacci","Integer sqrt")            #concatenate the names for the given information to put into columns and rows 
column_content<-c(12,13,FALSE,FALSE)                              #for the data frame

my.data<-data.frame(column_name,column_content,stringsAsFactors = FALSE)#creates the frame for the data and allows integers and strings together
my.data                                                           #views the new dataframe

n<-12^2                                                           #calculates the square of n = 144 ready to be added as a new row in the dataframe
n

newRow<-data.frame(column_name="N*N",                             #additional row to be added to the dataframe using the newRow
                   column_content=144)

my.data<-rbind(my.data,newRow)                                    #binding the new data row with the dataframe


my.data_small=my.data[c(1:2,4:5),]                                #removes the Fibonacci row - by choosing to leave that row our of the vector and 
my.data_small                                                     #renaming the vector as my.data_small
                                                                  #the new vector has had the Fibonacci row removed and a new row showing R*R as 144
