## Exercise 2. Character vector manipulation. # First create a script “exercise2.R” and save it to the “Rintro/day1” directory: you will save all your commands in it for that exercise. # 1. Create vector w as: w <- rep(c("miRNA", "mRNA"), c(2, 3)) # 2. View vector w in the console: # what is function rep() doing? # 3. Type table(w). What do you obtain? table(w) # 4. Type w[grep("mRNA", w)] and w[w == "mRNA"] # Is there a difference between the two outputs? w[grep("mRNA", w)] w[w == "mRNA"] # 5. Now type w[grep("RNA", w)] and w[w == "RNA"] # Is there a difference between the two ouputs? w[grep("RNA", w)] w[w == "RNA"] # 6. Create vector g as: g <- c("hsa-let-7a", "hsa-mir-1", "CLC", "DKK1", "LPA") # 7. How many elements do w and g contain? length(w) length(g) # 8. Assign names to each element of g: the names of g will be the characters contained in w! names(g) <- w ### OPTIONAL ### # 9. Replace all names of w that are “mRNA” with “Gene” names(g)[names(g)=="mRNA"] <- "Gene" # 10. Count how many miRNAs and how many Genes there are based on the column names. table(names(g))