Unify column to dataset and place this content below a table

2

I have table I have a column that is a dataset I need to separate this data and unify them to "standard columns".

I have already been able to separate the contents of the column by doing this:

nrow  temp area   sep1 sep2  sep3   sep4  sep5  sep6    
 1      x     x    x     x     x     x    NA    NA  
 2      x     x    x     x     x     x    x     NA  
 3      x     x    x     x     NA    NA   NA    NA  
100000  x     x    x     x     x     x    x     x  

But I still need to do this:

nrow  temp area   sep1 
 1      x     x    x     
 2      x     x    x     
 3      x     x    x     
100000  x     x    x     
nrow  temp area   sep2 
 1      x     x    x     
 2      x     x    x     
 3      x     x    x     
100000  x     x    x     
nrow  temp area   sep3 
 1      x     x    x     
 2      x     x    x     
 3      x     x    NA
100000  x     x    x     
nrow  temp area   sep4 
 1      x     x    x     
 2      x     x    x     
 3      x     x    NA
100000  x     x    x    
nrow  temp area   sep5 
 1      x     x    NA
 2      x     x    x     
 3      x     x    NA
100000  x     x    x     
nrow  temp area   sep6 
 1      x     x    NA
 2      x     x    NA    
 3      x     x    NA    
100000  x     x    x    

For this I tried to separate the columns and put them together with a loop of repetition, but I can not finish the code, below what I tried to do:

file_split = data.frame(colsplit(file_unic$UNIR, pattern=";",  names=paste0("sep", 1:34)))### separar coluna 

     for(i in 1:ncol(file_split)){
     uniao = cbind(file,sep) # juntar uma coluna previamente separada ao conjunto de dados
     }

However, I would still need to place one block below the other. How can I finish this?

    
asked by anonymous 24.05.2015 / 17:48

1 answer

3

It's not exactly what you want, but I think it can help.

I'll assume the following data.frame . Posting the expected result helps, but it would help more if you provided a more complete example in the question.

df <- data.frame(temp = c(10.1, 10.2, 10.3), 
                 area = c("A", "B", "C"), 
                 sep1 = c(1, 2, 3),
                 sep2 = c(10, 20, 30),
                 sep3 = c(100, 200, 300))

df;
  temp area sep1 sep2 sep3
1 10.1    A    1   10  100
2 10.2    B    2   20  200
3 10.3    C    3   30  300

Now the transformation I think can help you.

library(tidyr);
gather(df, sep, value, -temp, -area)

  temp area  sep value
1 10.1    A sep1     1
2 10.2    B sep1     2
3 10.3    C sep1     3
4 10.1    A sep2    10
5 10.2    B sep2    20
6 10.3    C sep2    30
7 10.1    A sep3   100
8 10.2    B sep3   200
9 10.3    C sep3   300
    
24.05.2015 / 18:17