I have a data frame which looks like this:
> df
V1 V2 V3 V4 V5 V6 V7
1 chr1:859582-899582 AHR.pfm 33440 - 9.188581 gcacgcaac NA
2 chr2:859582-899582 AIRE.pfm 7387 + 7.982141 TCTGGTTCAGTTGGATGC NA
3 chr1:859582-899582 AIRE.3.pfm 30639 - 8.127811 aaaaccaaacaaacaaaa NA
4 chr13:859582-899582 ALX1.pfm 11835 + 7.485710 GTAATTGTGTTA NA
5 chr21:859582-899582 ALX1.1.pfm 16260 + 9.529333 GTAATTAATTTA NA
6 chrX:859582-899582 ALX1.2.pfm 20686 + 9.241755 CTAATTAATTTA NA
I want to append multiple new columns to this dataframe and all of these columns will have information from within this data frame. Details are below:
- append column chr having values strsplit(df$V1,":")[[1]] (split first column values on : and assign the first index to this new column)
- append column start having values strsplit(df$V1,":")[[2]] => strsplit(df$V1,"-")[[1]] (split first column value firstly on : take 2nd index and then split it on - and assign first index to this new column)
- append column end having values df$start + length(df$V6) (add in the value of start, the length of characters in V6 column)
- append column TF having values strsplit(df$V2,".")[[1]] (split second column values on . and assign the first index to this new column
So that appended new column looks like:
chr1 859582 859591 AHR
chr2 859582 859600 AIRE
chr1 859582 859600 AIRE
chr13 859582 859594 ALX1
chr21 859582 859594 ALX1
chrX 859582 859594 ALX1