2017-07-15 2 views
0

Ich habe eine XDF-Datei in Microsoft R. Dies ist eine etwas vereinfachte Version meines Problems. Es hat 2 Spalten, eine Spalte ist kategorisch und enthält Indizes wie "1", "2", "3", usw. bis "10". Die zweite Spalte ist numerisch. Was ich tun möchte, ist eine 3-Spalte zu erstellen, das ist eine Transformation der 2. Spalte, aber bedingt durch die erste Spalte. I.e., etwas wieBedingte Transformation für XDF-Datei

if col1 == '1' then col3 = col2*0.50 else if col2 == '2' then col3 = col2*0.80 

und so weiter.

Ich weiß, Sie können Transformationen direkt in R machen, aber ich weiß nicht, wie so etwas zu erreichen ist.

Antwort

0

Funktioniert das?

MyDataset <- RxXdfData("./path/dataset.xdf") #the dataset you are using 

# replace transFormedCol with the name of the col you want to use 
rxDataStep(inData = MyDataset, 
      outFile = MyDataset, 
      transforms = list(
      transFormedCol = ifelse(col1 == '1',col2*0.5, 
            ifelse(col2 == '2', col2*0.8))), #etc... 
      overwrite = TRUE 
      )