Martyna K.
Martyna K.

Reputation: 3

Creating additional column which contain word from other column which contain 6 letters

I want to create new column in R and extract informations from other column, which have 6 letters and also start sentence in row.enter image description here

Do you have a idea, how should I do this?

Thank you for any information.

I tried use seperate function, but it didn't work.

Upvotes: 0

Views: 38

Answers (2)

jkatam
jkatam

Reputation: 3447

You can also try alternatively the substr function as below

Seqofviruses2 <- Seqofviruses %>% mutate(id=substr(seq.name,1,8), desc=substr(seq.name,9))

Upvotes: 0

agarcias
agarcias

Reputation: 26

You can solve this by using strsplit and sapply functions:

Seqofviruses$ID <- sapply(strsplit(Seqofviruses$seq.name," "), `[`, 1)
Seqofviruses$Definition <- sapply(strsplit(Seqofviruses$seq.name," "), `[`, 2)

Upvotes: 0

Related Questions