Hi community,
I was wondering if anyone can give any advice on this:
> Chr = c("NC1", "NC2", "NC3")
> Pos = c(150, 165, 190)
> Seq = c("GATCGATGAC", "GATG", "ACGTAG")
> df = data.frame(Chr, Pos, Seq)
> df
Chr Pos Seq
1 NC1 150 GATCGATGAC
2 NC2 165 GATG
3 NC3 190 ACGTAG
I want to count the characters of every row for the "Seq" Column and create a 4th column (let's call it NoCh) reporting the number of characters. First row GATCGATGAC is 10 characters. Second row GATG is 4 Third row ACGTAG is 6
Practically I want to do this:
> df
Chr Pos Seq NoCh
1 NC1 150 GATCGATGAC 10
2 NC2 165 GATG 4
3 NC3 190 ACGTAG 6
Any help would be much appreciated
Ioannis
Unless you're sure you want factors, create dataframes using
data.frame(...,stringsAsFactors=FALSE)
. That, or usetidyverse
and create atibble
.Yes I will import my files into R using
this will do the job. Thanks a lot Ram.