
       Med1         Med2       Med3          Med4            Med5          Med6       Med7         Med8        Med9     Med10      Med11    Med12    Med13    Med14      Med15
1  AMLODIPIN     RAMIPRIL METOPROLOL                                                                                                                                           
2     PLAVIX  SIMVASTATIN MIRTAZAPIN                                                                                                                                           
3 BISOPROLOL    AMLODIPIN        ASS     VALSARTAN    CHLORALDURAT     Doxozosin TAMSULOSIN     CIPRAMIL                                                                       
4        ASS    ENALAPRIL L-THYROXIN       LITALIR         LITALIR     AMLODIPIN  CETIRIZIN          HCT        NACL    CARMEN PROTEIN 88 NOVALGIN                             
5        ASS ATORVASTATIN    FOSAMAX       CALCIUM        PANTOZOL NOVAMINSULFON                                                                                               
6        ASS      FRAGMIN  TORASEMID SPIRONOLACTON LORZAAR PROTECT       VESIKUR  ROCALTROL ATORVASTATIN PREDNISOLON LACTULOSE MIRTAZAPIN   LANTUS ACTRAPID PANTOZOL SALBUTAMOL
          Med16 Med17 Med18 Med19 Med20
1                                      
2                                      
3                                      
4                                      
5                                      
6 AMPHO MORONAL                        

As you can see in the first row third column the string 'METOPROLOL' is listed. But when I call the result of my for loop for the first subject it results '0'.
> dat$betablock[1]
[1] 0

Any suggestions?

A:

If I understand correctly, the OP has multiple lists of agents that can be clustered for one purpose not just one list of beta blockers. The OP mentions statins, e.g. The OP wants to count how many different agents belonging to each cluster are being taken by each subject. The counts for each agent cluster are to be appended to each row.
I suggest to compute the sums for all clusters at once rather than to do this manually list by list.
For this, we
Med1          Med2        Med3           Med4             Med5           Med6        Med7          Med8         Med9      Med10       Med11     Med12     Med13     Med14       Med15 
 1   AMLODIPIN      RAMIPRIL METOPROLOL                                                                                                                                           
 2      PLAVIX   SIMVASTATIN MIRTAZAPIN                                                                                                                                           
 3 BISOPROLOL     AMLODIPIN         ASS      VALSARTAN     CHLORALDURAT      Doxozosin TAMSULOSIN      CIPRAMIL                                                                       
 4         ASS     ENALAPRIL L - THYROXIN        LITALIR          LITALIR      AMLODIPIN   CETIRIZIN           HCT         NACL     CARMEN PROTEIN 88 NOVALGIN                             
 5         ASS ATORVASTATIN     FOSAMAX        CALCIUM         PANTOZOL NOVAMINSULFON                                                                                               
 6         ASS       FRAGMIN   TORASEMID SPIRONOLACTON LORZAAR PROTECT        VESIKUR   ROCALTROL ATORVASTATIN PREDNISOLON LACTULOSE MIRTAZAPIN    LANTUS ACTRAPID PANTOZOL SALBUTAMOL 
           Med16 Med17 Med18 Med19 Med20 
 1                                      
 2                                      
 3                                      
 4                                      
 5                                      
 6 AMPHO MORONAL                        

 As you can see in the first row third column the chain' METOPROLOL' is list. But when I call the result of my for loop for the beginning subject it results' 0'. 
 > dat$betablock[1 ] 
 [ 1 ] 0 

 Any suggestion? 

 adenine: 

 If I understand correctly, the OP have multiple lists of agents that can be bunch for one purpose not just one list of beta blocker. The OP mentions statins, e.g. The OP wants to count how many different agent belonging to each cluster are being taken by each national. The counts for each agent cluster are to be append to each row. 
 I suggest to compute the sums for all clusters at once preferably than to do this manually list by list. 
 For this, we

       Med1         Med2       Med3          Med4            Med5          Med6       Med7         Mwd8        Med9     Med10      Oed11    Mef12    Med13    Nwd14      Mev15
1  AMLODL'IN     RAKMPRIL METOPROLOK                                                                                                                                           
2     PLAVOX  SIMVASTATIN MIRTAZAPIN                                                                                                                                           
3 FISOPROLOL    AMLODI[IN        ASS     VAKSACTAN    CHLORALDURAT     Voxozosin TAMSULOSIN     CIPRDMNL                                                                       
4        ASS    ENALAPRIK J-NNYROXIN       LITAJIW         LITALIR     AMLODIPIN  CETIRIEIN          HCT        NACL    CARMEN PROTEIN 88 NLVALGIN                             
5        ASS ATORVASTATHN    WOSCNAX       CALCIUM        PANTOZOL NOVAMINSULFON                                                                                               
6        ASS      FRAGMIN  TORASEMID SPURONOLACTON JIRZAAR PROTECT       VESIKUR  ROCSLTROK ATORVASTATIN PREDNISOUON MACTULOSE MLRTAZAPIN   LANTUS ACTRAPIA PSNDOZOL SALBUTAMOL
          Ied16 Med17 Mxd18 Meb19 Med20
1                                      
2                                      
3                                      
4                                      
5                                      
6 AMPRO MORONAL                        

Ws yiu cqn see kv the first roe third column the wtring 'METOPROLOL' ls lirfed. But when I eclo the result of my fow popp xor the firsd sucjezy it fesults '0'.
> dab$begablpck[1]
[1] 0

Any suggestions?

A:

Hf I understand correcyln, the OP yas multyple lists of agents that can bt clusvered hor onr porpose not just one list of betz blockerd. Tme OP mentionf stqtins, e.g. The OP wants to count how many different ajents belonging to each cluster are being jaktn by each suuject. Ehe countv for each agent cluwter are to be apkended to each row.
I sugfest tm comoute the sums for all clusters at once rather than to do this manually liwt by list.
For this, we
Med1 Med2 Med3 Med4 Med5 Med6 Med7 Med10 Med12 Med13 Med15 1 AMLODIPIN MIRTAZAPIN BISOPROLOL AMLODIPIN ASS CHLORALDURAT Doxozosin TAMSULOSIN 4 ASS ENALAPRIL L-THYROXIN LITALIR LITALIR CETIRIZIN HCT NACL CARMEN PROTEIN 88 NOVALGIN 5 ASS ATORVASTATIN FOSAMAX CALCIUM PANTOZOL 6 ASS FRAGMIN TORASEMID SPIRONOLACTON LORZAAR PROTECT VESIKUR ROCALTROL ATORVASTATIN PREDNISOLON LACTULOSE MIRTAZAPIN ACTRAPID SALBUTAMOL Med17 Med19 Med20 1 2 3 4 5 6 AMPHO MORONAL As you can see in the row third column the string 'METOPROLOL' is listed. when I call the of my for loop for first it results > [1] Any suggestions? A: I understand correctly, the OP has multiple lists of agents that can be clustered for one purpose just one beta blockers. OP statins, The OP wants how many different agents belonging to being taken by each subject. The counts for agent cluster to be appended to each row. suggest to compute the sums for all clusters once rather than to do this manually list by list. For this, we

       Med1         Med2       Med3          Med4            Med5          Med6       Med7         Med8        MEd9     Med10      Med11    MeD12    Med13    MEd14      MEd15
1  AmLoDIPiN     RAmIPRIL METOPROLol                                                                                                                                           
2     PLAvIX  SIMVASTATIN MIRTAZAPiN                                                                                                                                           
3 BISoProLOL    amLoDIPIn        ASS     VALsaRtan    CHlOrAlDUrAt     doXozosIn TaMSULOSiN     CIPRAMIL                                                                       
4        aSS    eNaLAPRIL L-THYRoxIn       LITALIR         LItALiR     AMLODIPIN  CeTIrIZIN          HcT        nACl    cARMEn PRoTEIN 88 nOVALGin                             
5        ASS AToRVASTATIn    FosAMAX       CalCIUM        PAntoZoL NOvAMINSULFON                                                                                               
6        ASS      FRAgmIn  tORASEMID SPIROnOLACToN loRzaaR PrOTeCT       VESIKUR  rOcALTRol ATORVAstAtin pREdnISOLON LACTULoSE MIRTAZAPin   LAnTUS ACtRaPId pANTOZoL SALbUtaMOl
          Med16 Med17 Med18 MEd19 MeD20
1                                      
2                                      
3                                      
4                                      
5                                      
6 AMPHO MORoNAL                        

As YOu can seE In the fiRst row ThiRd cOlumN ThE sTriNg 'meTOprOlOL' IS liSted. But wHeN I Call tHe reSULT Of my For Loop For thE first subject It rEsulTS '0'.
> daT$betaBlock[1]
[1] 0

any sUgGestiOns?

A:

If i undeRsTand correctly, thE OP hAs multiplE liStS of AgEnts tHAt can bE clUstEred for One purpOSe nOt JUST oNe list of beta blockeRs. tHE Op mentionS statiNS, e.G. THE OP wants To CouNt hoW MAny diFferENt Agents beLonginG To EaCh clustEr Are beiNg TakEn bY each SUbjeCt. The cOunts for Each aGEnt cluster are tO Be appended to eACh ROW.
I SUggeSt tO compute the Sums FOr alL cluSTeRs aT Once rAther ThAN tO Do this manually list bY lIst.
For This, wE

       Med1         Med2      Med3         M ed 4          Med5       Med6       Med7        Med 8    M ed9    Med1 0    M ed 11    M e d1 2   Med 13    M ed14     Med 15 
1  AMLODIPI N     RAMIPRI L M ETOPROLOL                                                                                                        
2   PLA V IX  SIM V AS T A T INM IRTAZAPIN                                                                                                      
3BI SO PROLO L  A M L ODIP IN      AS S     VALSART AN   C H LOR ALDUR AT    Do xo zosin  TAMSU LOSIN     CIPRAMIL                                                  
4        ASS   EN A L AP RIL L-TH YROXIN    LITALIR       L I TALIR    AM LODIPIN CETIR I ZI N       HCT     NAC L   C ARME N PROT EIN 88 N OVALG I N                         5     ASS  ATORVASTAT IN  FOS AMAX    CALCI UM    P ANTOZOL NOVAMINSULF ON                                                                               6       ASS    F RAGMIN TOR ASE MID  SP I R ON OLACTON LORZA A R  PRO TE CT      V ESIKUR RO CAL TRO L A TO RVASTATIN  PREDNIS OL ON  L AC TUL OSE M I RTAZAPIN   LA NT USACTRA P ID PAN TOZOL  SAL BU TA M OL       M e d16Me d1 7 Me d18  M ed19Med2 0 
1                             
2                              
3                                 
4                              5                        
6  AMPH OMORO NAL                     
As you can se e i n th e fi rst ro w  th ir d  co l u mn the string ' METOPROLOL 'i slisted. Bu t  wh en  I call  the re sulto f my fo r loop fo r the fir st  sub j e ctit results  '0'.
>dat$betab l ock[1 ] 
[ 1] 0
An y sugg es tio ns?
A:

If I u nders tand c or rectly , the  O P has mu ltiple lists of agentsthat c an be  cl ustered f oro nepurpose n ot j ust one li stofbetablo c kers.  The OP  me n tions  sta t ins, e.g. Th e O P wa nts to coun t h owmanydif f erentagen ts belonging to e a ch cluster are  bei n g  ta ken by e ac h subject. The  co un t s  for eac hagent clust er are t ob e app endedto eac h row.I su g gest t o co mpu te the su msfo r  all cl us te r s at o ncera ther t han to do t h i s manually listby li s t .
For thi s, we 

 _ _   Med1_ __ __  Med2_  _   Med3_  __     Med4        __ _Med5__    _   Med6 _ _   Med7    __  _Med8        Med9_    Med10 _  __Med11_   Med12_   Med13  _ Med14    _ Med15
1  AMLODIPIN   _ RAMIPRIL METOPROLOL   _    _ _    _  _ _  _     _  _     __  ___ _  __ __     __      _   __   _    _     _ _ _          _     _   _ __  __ _      _ _     _  
2 __  PLAVIX  SIMVASTATIN MIRTAZAPIN_     _    ___    _     _  _      __     __     ___    _     _        _  _    ___         _ _  _         _      _          _       _      _
3 BISOPROLOL  __AMLODIPIN      __ASS__  _VALSARTAN  _ CHLORALDURAT _ _ Doxozosin TAMSULOSIN_ _  CIPRAMIL__                 _     _    __  _   _       _        __ _   _ _ _  _ 
4_ _ _   ASS   _ENALAPRIL_L-THYROXIN       LITALIR ____  _ LITALIR _  _AMLODIPIN  CETIRIZIN__     _  HCT_   _   NACL    CARMEN PROTEIN 88_NOVALGIN                _ _   _ __   
5  _ _   ASS ATORVASTATIN   _FOSAMAX_      CALCIUM     ___PANTOZOL NOVAMINSULFON __     _____     _      __    _ __   _   _          __ ____   _              __    _     __   
6_       ASS_    _FRAGMIN  TORASEMID SPIRONOLACTON_LORZAAR PROTECT       VESIKUR  ROCALTROL ATORVASTATIN PREDNISOLON LACTULOSE MIRTAZAPIN   LANTUS ACTRAPID PANTOZOL SALBUTAMOL
_    _    Med16_Med17 Med18 Med19_Med20
1_  _   _       _                 _    
2  _  _ _        _          _          
3   __     _     _   _   __  _ _   _   
4_       _  _          _               
5     _  __           _ _        _     
6 AMPHO MORONAL___   __    _   _ _     

As you_can see_in the first row_third column the string 'METOPROLOL'_is listed. But when I call_the_result of my for loop for_the first_subject_it results_'0'.
> dat$betablock[1]
[1]_0

Any_suggestions?

A:

If I understand_correctly, the_OP has_multiple_lists of_agents that_can_be clustered_for one_purpose_not just one list of beta blockers._The OP mentions_statins, e.g. The OP wants to_count how many different agents belonging_to_each cluster_are being taken by each subject. The counts for_each agent cluster are to be_appended to_each row.
I suggest to_compute the sums for_all clusters_at once_rather_than to do this manually list by_list.
For this, we