2017-02-09 5 views
0

私はと呼ばれる7つのデータフレームを持っている:私は、このデータフレームのためにこれを行う必要がありループ内で異なるデータフレームを呼び出す方法は?

cod_jer_groups= 103 108 109 113 114 138 139 

muestra_suplentes_103$nrow=seq(from = 1, to = nrow(muestra_suplentes_103), by = 1) 
muestra_suplentes_108$nrow=seq(from = 1, to = nrow(muestra_suplentes_108), by = 1) 
muestra_suplentes_109$nrow=seq(from = 1, to = nrow(muestra_suplentes_109), by = 1) 
muestra_suplentes_113$nrow=seq(from = 1, to = nrow(muestra_suplentes_113), by = 1) 
muestra_suplentes_114$nrow=seq(from = 1, to = nrow(muestra_suplentes_114), by = 1) 
muestra_suplentes_138$nrow=seq(from = 1, to = nrow(muestra_suplentes_138), by = 1) 
muestra_suplentes_139$nrow=seq(from = 1, to = nrow(muestra_suplentes_139), by = 1) 

私はtraying午前私も呼ばれるベクトルを持って

"muestra_suplentes_103" 
"muestra suplentes_108" 
"muestra_suplentes_109" 
"muestra_suplentes_113" 
"muestra_suplentes_114" 
"muestra_suplentes_138" 
"muestra suplentes_139" 

をこれを行うには:

for(i in cod_jer_groups){ 
    muestra_suplentes$nrow= seq(from = 1, to = nrow(muestra_suplentes_i, by = 1)) 
    names(muestra_suplentes)[length(names(muestra_suplentes))]="nrow" 
    } 

私はそれが間違った呼び出し "muestra_suplentes_i"であることを知っていますが、私はそれを行う方法を知らない。

任意のsuugestion?

ありがとうございました!

+0

'get()'や 'set()'を使うことができます。ただし、 'list()'の使用を検討する必要があります。 – BigDataScientist

答えて

1

これは私がやることです。

# put the data.frames into a named list, where names correspond to data.frame names 
myList <- mget(ls(pattern="^muestra_suplentes") 

# fill in the column values 
myList <- lapply(myList, function(i) within(i, rowNum <- seq_len(nrow(i)))) 

this postにグレゴールの答えをチェックし、列にdata.framesを置くことは素晴らしいアイデアすることができる理由についての詳細を参照してください。

+0

ありがとうございます! – Natuk

関連する問題