title: R code automation
body: <p>I am doing PCA. Here is the code for the same-</p>
  
  <pre><code>### Read .csv file #####
     data&lt;-read.csv(file.choose(),header=T,sep=",")
     names(data)
     data$qcountry
  #### for the country-ARGENTINA#######
  ar_data&lt;-data[which(data$qcountry=="ar"),]
  ar_data$qcountry&lt;-NULL
  names(ar_data)
  names(ar_data)&lt;-c("01_insufficient_efficacy","02_safety_issues","03_inconvenient_dosage_regimen","04_price_issues"
                    ,"05_not_reimbursed","06_not_inculed_govt","07_insuficient_clinicaldata","08_previously_used","09_prescription_opted_for_some_patients","10_scientific_info_NA","12_involved_in_diff_clinical_trial"
                    ,"13_patient_inappropriate_for_TT","14_patient_inappropriate_Erb","16_patient_over_65","17_Erbitux_alternative","95_Others")
  
          names(ar_data)
        ar_data_wdt_zero_columns&lt;-ar_data[, colSums(ar_data != 0) &gt; 0]
  ####Testing multicollinearity####
         vif(ar_data_wdt_zero_columns)
  
  #### Testing appropriatness of PCA ####
            KMO(ar_data_wdt_zero_columns)
             cortest.bartlett(ar_data_wdt_zero_columns)
  
    #### Run PCA ####
         pca&lt;-prcomp(ar_data_wdt_zero_columns,center=F,scale=F)
         summary(pca)
  
   #### Compute the loadings for deciding the top4 most correlated variables###
        load&lt;-pca$rotation
        write.csv(load,"loadings_argentina_2015_Q4.csv")
  </code></pre>
  
  <p>I have shown here for the one country, I have done this for 9countries. For each country I have to run this code. I am sure there must be easier way to automate this code. Please suggest !!
  Thanks!!</p>