I have a list of company names that I would like to turn into tickers. Here is the reproducible code to create the list of names that I have:
companynames=structure(list(V1 = structure(1:41, .Label = c("AETNA INC", "ANTHEM INC",
"APPLE INC", "ASPEN INSURANCE HOLDINGS LTD", "BARRICK GOLD CORP",
"BEST BUY CO INC", "CAREFUSION CORP", "CBS CORP-CLASS B NON VOTING",
"CIGNA CORP", "COMPUTER SCIENCES CORP", "COMPUWARE CORP", "COVENTRY HEALTH CARE INC",
"DELPHI AUTOMOTIVE PLC", "DST SYSTEMS INC", "EINSTEIN NOAH RESTAURANT GRO",
"ENSCO PLC-CL A", "EXPEDIA INC", "FIFTH STREET FINANCE CORP",
"GENERAL MOTORS CO", "GENWORTH FINANCIAL INC-CL A", "GREEN BRICK PARTNERS INC",
"HESS CORP", "HUMANA INC", "HUNTINGTON INGALLS INDUSTRIE", "LEGG MASON INC",
"MARKET VECTORS GOLD MINERS", "MARVELL TECHNOLOGY GROUP LTD",
"MICROSOFT CORP", "NCR CORPORATION", "NVR INC", "OAKTREE CAPITAL GROUP LLC",
"REPUBLIC AIRWAYS HOLDINGS IN", "SEAGATE TECHNOLOGY", "SPRINT COMMUNICATIONS INC",
"STARZ - A", "STATE BANK FINANCIAL CORP", "SYMMETRICOM INC",
"TESSERA TECHNOLOGIES INC", "UNITEDHEALTH GROUP INC", "VIRGIN MEDIA INC/OLD",
"XEROX CORP"), class = "factor")), .Names = "V1", class = "data.frame", row.names = c(NA,
-41L))
This gives me something along the lines of:
head(companynames)
V1
1 AETNA INC
2 ANTHEM INC
3 APPLE INC
4 ASPEN INSURANCE HOLDINGS LTD
5 BARRICK GOLD CORP
6 BEST BUY CO INC
I would like another column that outputed the tickers of each of these companies. So for the first row I should get AET, second row would be ATHN, and third row would be AAPL, etc. My example is in R, but any solution in python or R would be very helpful. I am not sure if there is already a function that does it or how the best approach would be to create a function if it does not exist.