Make variables created with lapply allocated in their respective dataframe within a list

3

I use the lapply function and want the results to return within their respective dataframe within the list. Consider the following function:

x<-lapply(list,function(x)paste(x$Sigla,x$Município,sep='')) # onde 'Sigla' e 'Município'são variáveis em comum em todos os dataframes

This returns me a list x with only the results (concatenated).

How do I adjust this function to get what I want?

I can not post dput because the list is too large.

    
asked by anonymous 01.10.2018 / 21:13

1 answer

3

Using the following example:

lista <- list(
  A = data.frame(Sigla = sample(LETTERS, 20, rep = T), Município = sample(letters, 20, rep = T)),
  B = data.frame(Sigla = sample(LETTERS, 20, rep = T), Município = sample(letters, 20, rep = T)),
  C = data.frame(Sigla = sample(LETTERS, 20, rep = T), Município = sample(letters, 20, rep = T))
)

You can use to allocate the new variable within its respective dataframe with the command cbind :

lapply(lista, function(x)cbind(x, Variável = paste(x$Sigla,x$Município,sep='')))
    
01.10.2018 / 21:32