IRT
IRT

Reputation: 209

extract from list of elements R with specific length

I have a list of items: List_item is the following (extract):

List_item=c("SA","SB","SC","SC1","SC11","SC12","SC13","SC2","SC21")

from which I would like to extract and put in a list "List_2letters" the elements of length 2. Later on this List_2letters will use it to do some operations. I googled a bit but cold not find a solution.

Upvotes: 1

Views: 529

Answers (1)

JRR
JRR

Reputation: 3223

List_2letters = List_item[nchar(List_item) == 2]

Upvotes: 2

Related Questions