Concatenate values within the same columns of the data frame in the R software

2

Can anyone help me? Anyway, I'm already grateful!

    
asked by anonymous 09.11.2016 / 01:25

2 answers

2

Search for help with the paste function. If your frame data is df you can do:

re1<- apply(df[1:3,-1],2,paste,collapse="_")
nomes<- c(df[3,1],re1)

New df:

df1 <- df[-c(1:3),]
colnames(df1)<- nomes
    
09.11.2016 / 09:20
-2

I've already discovered ...

The correct one would be:

N_row_concatenate<-3 # Digite ao lado o número de   linhas que você deseja 
                     #concaternar para formar o nome da nova variável!!!

Head_Name <-apply(Df[1:N_row_concatenate,-(1+ncol(Df))],2,paste,collapse="_")
New_Df <- Df[-c(1:N_row_concatenate),]
colnames(New_Df)<- Head_Name
New_Df_long <- melt(New_Df, id=c(Head_Name[1:1])) 

Anyway thank you very much for the initial idea. It was great!

    
16.11.2016 / 23:36