Changing the name of rows from a list in R using lapply from a list variable

2

I have a list called dataList and would like the name of the lines to be the same as a variable called CNPJ that is within that list. For this, I first applied:

dadosLista<-lapply(dadosLista, "rownames<-", dadosLista$CNPJ)

However, dataList $ CNPJ is considered an empty variable. So I created the CNPJ list:

CNPJ<-lapply(dadosLista, '[', 3)

And then:

dadosLista<-lapply(dadosLista, "rownames<-", CNPJ)

The error appeared:

Error in 'row.names<-.data.frame'('*tmp*', value = value) : 
'row.names' com comprimento inválido

It should be some problem I'm having with the understanding of lapply.

    
asked by anonymous 30.06.2017 / 15:55

1 answer

1

I solved this problem using a for statement as follows:

for (i in 1:340){
rownames(dadosLista[[i]])<-dadosLista[[i]][,c(3)]
}

Where column 3 represents the desired values for row names.

    
03.07.2017 / 18:56