[R] How can I delete column yhat AND STILL retain the order of Response?

Rui Barradas ruipbarradas at sapo.pt
Sat Apr 1 20:59:25 CEST 2017


1) We don't have access to your file firstRdata.csv so what I'll say is 
just an untested guess. You can post some of your data with the 
following R command.

dput(head(Response, 20))  # paste the output of this in a mail

2) First you use read.csv that outputs a data.frame and then do 
data.frame(Response). Useless. Response already is a df.

3) I believe the trouble you're facing comes from your use of attach(). 
This function is _never_ needed and is cause of all sorts of bugs. In 
particular, what you are ordering is the attached copy of Response, and 
all changes you do to it will only have effect on the copy. The original 
is left as it were.

So run the same code (with the obvious bug yhatResponse$yhat corrected) 
but eliminating the 'attach' instruction. And see if it reorders Response.

Hope this helps,

Rui Barradas

Em 01-04-2017 17:32, BR_email escreveu:
> Response    <- read.csv("C:/R_Data/firstRdata.csv", sep=",", header=TRUE)
> Response
> Response    <- data.frame(Response)
> attach(Response)
> Response
> Response    <- Response[order(-yhat),]
> Response    <- Response[rev(order(yhatResponse$yhat)),]
> Response

More information about the R-help mailing list