Создание новой таблицы из большой таблицы .csv

У меня есть большой файл .csv. Я хотел бы отфильтровать этот файл в новую таблицу.

Например, у меня есть файл .csv, как показано ниже:

   f1 f2  f3 f4  f5  f6 f7 f9  f10  f11 
t1  1  0  1   0  1  0   0  0   0    1 
t2  1  0  0   0  0  1   1  1   1    1 
t3  0  0  0   0  0  0   0  0   0    0 
t4  1  0  0   0  1  0   0  0   0    0 
t5  0  0  0   0  0  0   0  0   0    0 
t6  0  0  0   0  0  0   0  0   0    0 

I have a table (as above)

What I want to do is, I want to have new table for each row (meaning that, I will have new table for all rows. e.g, new table for row t1, new table for row t2, new table for row t3 and etc). As in this example, I should have 6 new tables.

To develop new table for each row, there is a condition that need to meet. New table should look at every value in each column. And if the column has a same value with other column in other row (which is value 1), it should be grouped together.

Как и в этом примере, новая таблица для t1 будет состоять из t1, t2, t4, потому что значение в столбце f1 имеет то же значение (равное 1) со значением в f1 для строк t2 и t4, также значение в f5 равно значению в f5 для строки t4, а значение в f11 равно значению в f11 для строки t2). Значит, это будет проверять каждый столбец. Один из выходных данных для должен быть таким:

       f1 f2  f3 f4  f5  f6 f7 f9  f10  f11 
    t1  1  0  1   0  1  0   0  0   0    1 
    t2  1  0  0   0  0  1   1  1   1    1 
    t4  1  0  0   0  1  0   0  0   0    0 

As for t2, row t2 should be grouped with t4 because value in f1 in t1 and value f1 in t4 is equal. However, t2 should not consider the earlier row (as in this example, it should not consider t1). Output should be like this:

  f1 f2  f3 f4  f5  f6 f7 f9  f10  f11 
t2  1  0  0   0  0  1   1  1   1    1 
t4  1  0  0   0  1  0   0  0   0    0 

Similar to other rows (row t3,t4,t5 and t6), it should look at every value in each column. And if the column has a same value with other column in other row (which is value 1), it should be grouped together.

New table (with row and column header) should be then saved in a new .csv file. The file should be renamed using its row name. for example, as for t1, it should be saved as t1.csv.

This is only a simple example. The proposed solution here will be applied in other big table of data. I need to read abc.csv file. Meaning that, it might be more than 100+ new table will be created (when I used original data).

пока я использовал этот код:

a.files <- grep("^Task_vs_Files", dir(), value=TRUE) 
a.files

for(i in 1:length(a.files))
   dat <- read.table(file=a.files[i], header=T, sep=",", row.names=1) 


      (sapply(1:nrow(dat), function(x) if (dat[x,]==1)  #check row
            (sapply(1:nrow(dat), function(y) if (dat[,y]==1) #check column

            { 
                   write.csv( dat[(dat[[x,y]]==1 ) & (1:nrow(dat) >= x) , ] , file = paste("Files_", x) ) #save file based on row names
            } 
            else {NULL} ))

вывод из a.files:

[1] "Task_vs_Files_Proj.csv"  "Task_vs_Files_Whirr.csv"

набор данных из одного файла (Task_vs_Files_Proj.csv)

       pom.xml. ZooKeeper.java HBase.java Hadoop.java. BasicServer.java. Abstract.java. HBaseRegion.java
WHIRR-25        1              0          1            0                 1              1                1
WHIRR-28        1              0          1            0                 0              1                0
WHIRR-55        0              0          1            0                 0              0                0
WHIRR-61        0              0          0            0                 0              1                0
WHIRR-76        0              0          1            0                 0              0                0
WHIRR-87        1              1          1            0                 0              1                1
WHIRR-92        1              0          0            1                 0              1                1

Ценю помощь эксперта!

Ответы на вопрос(1)

Ваш ответ на вопрос