I created a data frame which consists of 3 columns x,y,z. I would like to order my data frame according to decreasing order of column z. The below code works but its output does not correct since it gives correct order with the 2 digit numbers. LEt's say z=8,9,7,6,3,12,13,14,11. The below code orders z like z=9,8,7,6,3,14,13,12,11 . I could not figure out how to overcome this issue.
for (i in 1:nrow(temp)){
if(identical(s,temp[i,2])==TRUE){
x[k]<-temp[i,1]
y[k]<-temp[i,2]
z[k]<-as.numeric(temp[i,4])
k<-k+1
}}
frame<-data.frame(cbind(x,y,z))
print(frame[with(frame, order(z)), ])
Aucun commentaire:
Enregistrer un commentaire