Title: List member reference
Tags: r;list;reference
Question: I have  a list of strings like this, and I want to get all the brand names:
s = c("FERRARI - 612 SCAGLIETTI" ,"PORSCHE - 918",  "ASTON MARTIN - DBS")
tt= strsplit(s," -")
but here tt is a list of lists. How could slice this tt? I tried
tt[[1:length(tt)]][1]
but got this error:
Error in tt[[1:length(tt)]] : recursive indexing failed at level 2.
Any suggestion?

Here is the accepted answer: We can use sub to match zero or more space (\\s*) followed by a - followed by other characters and replace it with blank ("")
sub("\\s*-.*", "", s)
#[1] "FERRARI"      "PORSCHE"      "ASTON MARTIN"
Regarding the 'tt', it is a list, so we can loop through the list with lapply/sapply/vapply etc and get the first element
sapply(tt, head, 1)
#[1] "FERRARI"      "PORSCHE"      "ASTON MARTIN"
Comment for this answer: This is smart. Thank you.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:02/15/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<r><list><reference>', 'Title': 'List member reference', 'ViewCount': 108, 'id': 42255398, 'user_AboutMe': '', 'user_AccountId': 4991285.0, 'user_DisplayName': 'newleaf', 'user_Reputation': 1997.0, 'user_Views': 175.0, 'user_id': 4013447.0}}