Ok das ist sehr einfach, aber ich versuche, eine 'verschachtelte' (2-stufig) Liste in R. zu erstellenR - schaffen Multi-Level-Liste
Ich habe vier Dateien verwiesen wird dies mögen:
files=c('path-to-file1',
'path-to-file2',
'path-to-file3',
'path-to-file4')
auf der anderen Seite, ich habe vier verschiedene Operationen, die ich für jede Datei ausführen müssen:
ops=c('operation1,
operation2,
operation3,
operation4')
ich zwei tue „für“ Schleifen (eine über Dateien und über Operationen) und Daher muss ich eine zweistufige Liste füllen, die oder sein muss nisiert wie folgt aus:
- the 1st element of the first level is "file1";
- the 1st element of the second level is "operation1"
- the 2nd element of the second level is "operation2"
- the 3nd element of the second level is "operation3"
- the 4nd element of the second level is "operation4"
- the 2nd element of the first level is "file2";
- the 1st element of the second level is "operation1"
- the 2nd element of the second level is "operation2"
- the 3nd element of the second level is "operation3"
- the 4nd element of the second level is "operation4"
- and so on...
Was ist der beste Weg, um eine Multi-Level-Liste wie folgt zu erstellen?
EDIT: Dies ist eine Art, was ich suche:
files=c('path-to-file1',
'path-to-file2',
'path-to-file3',
'path-to-file4')
ops=c('operation1,
operation2,
operation3,
operation4')
# Create empty list to hold "operations" objects
list.ops = vector('list', length(ops))
# Create multi-level list lo hold both "files" and "operations" objects
multi.list = ? (how to create it? see loops below)
for (i in 1:length(files)){
for (j in 1:length(ops)){
(do some stuff)
list.ops[[j]] = result of some operations
}
multi.list[[i]][[j]] = list.ops[[j]]
}
Was ist Betrieb? Ist es eine Funktion? Basierend auf Ihrem Beispiel ist es eine einzelne Zeichenfolge. Bitte zeigen Sie ein kleines reproduzierbares Beispiel für andere an Ihrem Problem zu arbeiten – akrun
@akrun die Operation ist wirklich eine Reihe von mathematischen Berechnungen. Ziemlich schwierig, mit einem aussagekräftigen Datensatz zu reproduzieren, weil wir über Satellitenbilder sprechen, die riesig sind ... – thiagoveloso
@akrun, Ich habe die Frage bearbeitet, indem ich ähnliche Schleifen wie in meinem Skript hinzugefügt habe. Hoffentlich wird es leichter zu verstehen ... – thiagoveloso