So I’m trying to do these problems in R in order to learn it.
But I’m stuck on the first problem to simply count the frequency of charactors in a string. I can’t even seem to get past loading the data and getting to the string 🙁
How do I do something like print the first charactor of the string from this text file?
Here’s what I’ve tried so far:
> rosalind_dna <- read.table("~/Downloads/rosalind_dna.txt", quote="")
Warning message:
In read.table("~/Downloads/rosalind_dna.txt", quote = "") :
incomplete final line found by readTableHeader on '~/Downloads/rosalind_dna.txt'
> viewData(rosalind_dna)
> str(rosalind_dna[1,1,1])
Factor w/ 1 level "GGCCCGGTTACTGCGACTGAACAATCAAAATCTGAAGCATTTAAGCCAAACCAATTGAGATCGACTTACGAGCGATAACCCAGTATATTCAAGTGCTACTGATGAGGCGTGGTCCCCTGGACAAGGC"| __truncated__: 1
What you’ve done so far is just fine.
read.tablereturns a data frame. In this case, you just get a data frame with a single column and only a single value in that column.By default, R will convert character columns in data frames to factors. You can convert it back using
as.character.Then you’ll simply want to split that single string into individual characters (
strsplit) and then make a table (table). (No need for loops!)Here’s a toy example illustrating all the functions I mentioned: