I have a data.frame with three rows and five collumns. I want use IF statement to apply an iterative upgrade of my results until that my conditions will be achieved. More specifically, I want perform a cumulative column reduction in my dataframe. The condition is that the final datarame will contain values in which the summ of columns be less or equal 9 (V1,V2 and V3). I have been working on a code, however I'm with dificult to apply the cumulative iteration parameter. Untill now my code is:
dataset<-data.frame(V1=c(2,3,4),V2=c(1,2,3),V3=c(0,1,1),V4=c(5,5,3),V5=c(7,8,9))
my.func<-function(x){
df<-data.frame(Class=colnames(x), Val = colSums(x), row.names = 1:length(x))
if(any(df$Val>9)){
z<-as.character(df[which.max(df$Val),1])
w<-x[,-which(colnames(x)==z)]
dados<-data.frame(Class=colnames(w), Val = colSums(w), row.names = 1:length(w))
if(any(dados$Val<=9)){
h<-dados
}
return(h)
}
}
This code partially works. My problem with this lines is that the code dont upgrade the operation based in the last dataframe modification. Someone could help to understand where the code fail?
Aucun commentaire:
Enregistrer un commentaire