BR_email
2017-Apr-01 16:32 UTC
[R] How can I delete column yhat AND STILL retain the order of Response?
Hi R'ers: Attached, my R_code, the dataset, and my query. How can I delete column yhat AND STILL retain the order of Response? When I remove yhat, the resultant dataset has Response in the original order, not the reordered version I created. Any help is greatly accepted. Thank you, in advance. Bruce -- -------------- next part -------------- #How can I delete column yhat AND STILL retain the order of Response? 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
Rui Barradas
2017-Apr-01 18:59 UTC
[R] How can I delete column yhat AND STILL retain the order of Response?
Hello, 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
BR_email
2017-Apr-01 19:13 UTC
[R] How can I delete column yhat AND STILL retain the order of Response?
Rui: Thanks. I will try it. FYI: I did attached the data, but here it is re-attached. Thanks, again. Bruce Bruce Ratner, Ph.D. The Significant Statistician? (516) 791-3544 Statistical Predictive Analtyics -- www.DMSTAT1.com Machine-Learning Data Mining and Modeling -- www.GenIQ.net Rui Barradas wrote:> Hello, > > 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 > > >
BR_email
2017-Apr-01 19:18 UTC
[R] How can I delete column yhat AND STILL retain the order of Response?
Rui: Success! Thank you so much. Bruce Rui Barradas wrote:> Hello, > > 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 > > >