Note that there are some explanatory texts on larger screens.

plurals
  1. POLooping and storing results over many data frames
    primarykey
    data
    text
    <p>I want to to perform at least six looping steps in R. My data sets are <a href="https://drive.google.com/folderview?id=0B90n5RdIvP6qbkNaUG1rTXN5OFE&amp;usp=sharing" rel="nofollow">28 files</a> stored in one folder. Each file has 22 rows (21 individual cases and one row for column names) and columns as follows: Id, id, PC1, PC2….PC20.</p> <p>I intend to: </p> <ol> <li>read each file into R as a data frame</li> <li>delete first column named “Id” in the each data frame </li> <li><p>arrange each data frame as follows:</p> <ul> <li><p>first column should be “id” and </p></li> <li><p>next ten columns should be first ten PCs (PC1, PC2, …PC10)</p></li> </ul></li> <li>sort each data frame according to “id” (data frames should have the same order of individuals and their respective PC’s scores)</li> <li>perform pairwise comparison by <strong>protest function</strong> in the <em>vegan</em> package among all possible pair’s combinations (378 combinations)</li> <li>store result of each pair’s comparison in a symmetric (28*28) matrix which will be used in further analysis</li> </ol> <p>At the moment I am able to do it manually for each pair of data (code is below):</p> <pre><code>## 1. step ## read files into R as a data frame c_2d_hand_1a&lt;-read.table("https://googledrive.com/host/0B90n5RdIvP6qbkNaUG1rTXN5OFE/PC scores, c_2d_hand-1a, Symmetric component.txt",header=T) c_2d_hand_1b&lt;-read.table("https://googledrive.com/host/0B90n5RdIvP6qbkNaUG1rTXN5OFE/PC scores, c_2d_hand-1b, Symmetric component.txt",header=T) ## 2. step ## delete first column named “Id” in the each data frame c_2d_hand_1a[,1]&lt;-NULL c_2d_hand_1b[,1]&lt;-NULL ## 3. step ## arrange each data frame that have 21 rows and 11 columns (id,PC1,PC2..PC10) c_2d_hand_1a&lt;-c_2d_hand_1a[,1:11] c_2d_hand_1b&lt;-c_2d_hand_1b[,1:11] ## 4. step ## sort each data frame according to “id” c_2d_hand_1a&lt;-c_2d_hand_1a[order(c_2d_hand_1a$id),] c_2d_hand_1b&lt;-c_2d_hand_1b[order(c_2d_hand_1b$id),] ## 5. step ## perform pairwise comparison by protest function library(permute) library(vegan) c_2d_hand_1a_c_2d_hand_1b&lt;-protest(c_2d_hand_1a[,2:ncol(c_2d_hand_1a)],c_2d_hand_1b[,2:ncol(c_2d_hand_1b)],permutations=10000) summary(c_2d_hand_1a_c_2d_hand_1b)[2] ## or c_2d_hand_1a_c_2d_hand_1b[3] </code></pre> <p>Since I am a newbie in data handling/manipulation in R, my self-learning skills are suitable to perform respective steps manually, typing codes for each data set and perform each pairwise comparisons at the time. Since I need to perform those six steps 378 times, manual typing would be exhaustive and time consuming. </p> <p>I tried to import files as a list and tried several operations, but I was unsuccessful. Specifically, using list.files(), I made the list, called “probe”. I was able to select certain data frame using e.g. probe[2]. Also I could assess column “Id” by e.g. probe&#91;2]&#91;1], and deleted it by probe&#91;2]&#91;1]&lt;-NULL. But when I tried to work with for loop, I was stuck. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload