#Lowri Jones #1801539 #TASK 2 # Question 1 for(i in 1:30){ #This is a for loop that will run 30 times incrementing by 1 each time from 1 to 30. if(i==1){ #if 'i' is equal to the number one. y<-c(i, i) #This will put 'i' into the variable y twice. print(y) #This will display y } else if ((i%%2)==0){ #If 'i' isn't 1, and is an even number then this code will be followed. y<-c(i, i/2) #Y will now become i and i divided by 2 print(y) #This will display y } else { #If I isnt an even number and isnt equal to one, this code will be followed. y<-c(i, i*3+1) #Y will now become i and i multiplied by 3 plus 1 print(y) #This will display y } } #Question 2 - Is n a fibonacci number and does it have an integer square root? #Question 3 - create a dataframe to contain certain data. columnname<-c("N", "Terms", "Fibonacci", "Interger sqrt") column_contents<-c(i,"","","") d<-data.frame(columnname, column_contents, stringsAsFactors = FALSE) d #Above, I have created a dataframe with the correct headings however as I wasn't able to complete the first part of task 2, i am unable to fill in all of the rows. #Question 4 -display the data frame d #The above code 'd' will display the whole data frame whereas the code below will display different parts of the dataframe seperately. d[[1]] d&columnname d&column_contents d[1,1] #Question 5 - Replace Fibonacci column with a column containing the value of n2 and call this column n*n and preview the updated data frame