These exercises cover the sections of functions in R Introduction to R.

– Create a function which takes one argument and finds the smallest number whose factorial is greater than that argument.(Look at answer from previous exercises)

– Create a function which takes a vector argument and returns both the number of even perfect squares and a vector of perfect squares found in the vector argument.

– Create a function which takes an argument of the directory containing expression files and the name of the annotation file and writes a the table with all samples’ expression results and all annotation to file. (Look at answer from previous exercises)

– Adapt the above function to also write a t-test result table filtered by the p-value cut-off. An additional argument specifying the allocation a samples into groups must be specified.(Look at answer from previous exercises)

To retrieve the indicies of the first occurence of every element in one vector in a second vector you can use the match() function.

allSamples <- c("sample1.txt","sample2.txt","sample3.txt","sample4.txt","sample5.txt","sample5.txt")
testSamples <- c("sample1.txt","sample5.txt")
match(testSamples,allSamples)
## [1] 1 5
allSamples[match(testSamples,allSamples)]
## [1] "sample1.txt" "sample5.txt"

To find all occurences of vector in another you can use the %in% operator

allSamples <- c("sample1.txt","sample2.txt","sample3.txt","sample4.txt","sample5.txt")
testSamples <- c("sample1.txt","sample5.txt")
allSamples %in% testSamples
## [1]  TRUE FALSE FALSE FALSE  TRUE
allSamples[allSamples %in% testSamples]
## [1] "sample1.txt" "sample5.txt"