[R] Looking for a package to replace xtable

peter dalgaard pdalgd at gmail.com
Sat Apr 22 15:38:22 CEST 2017


> On 22 Apr 2017, at 13:47 , BR_email <br at dmstat1.com> wrote:
> 
> David:
> This is my last query on this issue.
> I thank you, again, for your patience,
> without perhaps your not understanding what drives (bugs) me.
> 
> Is there a more efficient way of writing the code, below,
> which is replicating the original dataset Response 5 times?
> 
> Response5x <- rbind(Response, Response, Response, Response, Response)

Dunno about the efficiency, but there is

do.call(rbind, rep(list(Response), 5))

-pd

> 
> Regards,
> Bruce
> 
> 
> BR_email wrote:
>> David:
>> Its' not going my way today.
>> I'll try to work with all that you provided.
>> It's late Friday and I cannot impose on you much more.
>> Thank you.
>> If I may, after I rework it, I'll contact you, okay?
>> Have great weekend. And thanks, again.
>> Bruce
>> FYI: Below are where the error messages start:
>> 
>> R> Decile_RespRate <- (No_Resp/No_Inds) Error: object 'No_Resp' not found R> R> dec_mean_wt_R_nRD <- cbind(dec_mean_wt_R_nR, Cum_RespRate, Decile_RespRate) Error in cbind(dec_mean_wt_R_nR, Cum_RespRate, Decile_RespRate) : object 'Decile_RespRate' not found R> R> R> R> avg_RR <- dec_mean_wt_R_nRD[10,7] Error: object 'dec_mean_wt_R_nRD' not found R> Cum_Lift <- (Cum_RespRate/avg_RR)*100 Error: object 'avg_RR' not found R> R> DECILE <- c("top","2","3","4","5","6","7","8","9","bot") R> R> dec_mean_wt_R_nRDL <- cbind(DECILE, dec_mean_wt_R_nRD, Cum_Lift, stringsAsFactors=FALSE) Error in cbind(DECILE, dec_mean_wt_R_nRD, Cum_Lift, stringsAsFactors = FALSE) : object 'dec_mean_wt_R_nRD' not found R> dec_mean_wt_R_nRDL <- dec_mean_wt_R_nRDL[,c(1,3,4,9,8,10)] Error: object 'dec_mean_wt_R_nRDL' not found R> R> R> total_line<-cbind(DECILE="Total", + as.data.frame(matrix(c(colSums(dec_mean_wt_R_nRDL[ , 2:3]), rep(NA, 3)),nrow=1))) Error in is.data.frame(x) : object 'dec_mean_wt_R_nRDL' not found R> R> names(total_line)<-names(dec_mean_wt_R_nRDL) Error: object 'dec_mean_wt_R_nRDL' not found R> dec_mean_wt_R_nRDLT<-rbind(dec_mean_wt_R_nRDL,total_line) Error in rbind(dec_mean_wt_R_nRDL, total_line) : object 'dec_mean_wt_R_nRDL' not found R> decile_table <- dec_mean_wt_R_nRDLT Error: object 'dec_mean_wt_R_nRDLT' not found R> decile_table Error: object 'decile_table' not found R> R> #Install the xtable package: install.packages("xtable") R> #Load the xtable package: R> library(xtable) R> R> DECILE_TABLE <-xtable(decile_table) Error in xtable(decile_table) : object 'decile_table' not found R> DECILE_TABLE Error: object 'DECILE_TABLE' not found R> R> R> print.xtable(DECILE_TABLE, type="html",file="C:/R_Data/DecileTable.html", include.rownames=FALSE) Error in print.xtable(DECILE_TABLE, type = "html", file = "C:/R_Data/DecileTable.html", : object 'DECILE_TABLE' not found
>> 
>> R>
>> 
>> 
>> 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
>> 
>> 
>> David L Carlson wrote:
>>> I've attached a modification of your script file (called .txt so it doesn't get stripped). See if this does what you want.
>>> 
>>> David C
>>> 
>>> -----Original Message-----
>>> From: Bruce Ratner PhD [mailto:br at dmstat1.com]
>>> Sent: Friday, April 21, 2017 3:46 PM
>>> To: David L Carlson <dcarlson at tamu.edu>
>>> Cc: r-help at r-project.org
>>> Subject: Re: [R] Looking for a package to replace xtable
>>> 
>>> David:
>>> Correction: I do need a data frame because from the order Response column I create a data frame as per all my calculated columns, yielding the five column decile table.
>>> I used your latest corrections but something buggy is a happenin'.
>>> 
>>> Bruce
>>> ______________
>>> Bruce Ratner PhD
>>> The Significant Statistician™
>>> (516) 791-3544
>>> Statistical Predictive Analytics -- www.DMSTAT1.com
>>> Machine-Learning Data Mining -- www.GenIQ.net
>>> 
>>> 
>>> 
>>>> On Apr 21, 2017, at 4:25 PM, Bruce Ratner PhD <br at dmstat1.com> wrote:
>>>> 
>>>> David:
>>>> Response=rbinom(50,1,0.2), and yhat=runif(50) are simulating the output of a say logistic model, where Response is actual 0-1 responses, and yhat is the predicted
>>>> response variable.
>>>> I usually resample the original data to get some noise out of the data. I find it valuable if I can resample from a large sample than the original.
>>>> (I know this is viewed by some as unorthodox.)
>>>> 
>>>> Your point: I only need Response as a column vector.
>>>> That said, what would you alter, please?
>>>> Thanks for your time.
>>>> Regards,
>>>> Bruce
>>>> 
>>>> ______________
>>>> Bruce Ratner PhD
>>>> The Significant Statistician™
>>>> (516) 791-3544
>>>> Statistical Predictive Analytics -- www.DMSTAT1.com
>>>> Machine-Learning Data Mining -- www.GenIQ.net
>>>> 
>>>> 
>>>> 
>>>>> On Apr 21, 2017, at 3:43 PM, David L Carlson <dcarlson at tamu.edu> wrote:
>>>>> 
>>>>> You have an issue at the top with
>>>>> 
>>>>> Resp <- data.frame(Response=rbinom(50,1,0.2), yhat=runif(50))
>>>>> Resp <- Resp[order(Response$yhat,decreasing=TRUE),]
>>>>> 
>>>>> Since Response$yhat has not been defined at this point. Presumably you want
>>>>> 
>>>>> Resp <- Resp[order(Resp$yhat,decreasing=TRUE),]
>>>>> 
>>>>> The main issue is that you have a variable Response that is located in a data frame called ResponseX10.
>>>>> 
>>>>> In creating cum_R you need
>>>>> 
>>>>> cum_R    <- with(ResponseX10, cumsum(Response))
>>>>> 
>>>>> then dec_mean
>>>>> 
>>>>> dec_mean <- with(ResponseX10, aggregate(Response, by=list(decc), mean))
>>>>> 
>>>>> then dd
>>>>> 
>>>>> dd  <- with(ResponseX10, cbind(Response, dd_))
>>>>> 
>>>>> 
>>>>> You might consider if Response really needs to be inside a data frame that consists of a single column (maybe you do if you need to keep track of the row numbers). If you just worked with the vector Response, you would not have to use with() or attach().
>>>>> 
>>>>> I'm not sure what the first few lines of your code are intended to do. You choose random binomial values and uniform random values and then order the first by the second. But rbinom() is selecting random values so what is the purpose of randomizing random values? If the real data consist of a vector of 1's and 0's and those need to be randomized, sample(data) will do it for you.
>>>>> 
>>>>> Then those numbers are replicated 10 times. Why not just select 500 values using rbinom() initially?
>>>>> 
>>>>> 
>>>>> David C
>>>>> 
>>>>> 
>>>>> -----Original Message-----
>>>>> From: BR_email [mailto:br at dmstat1.com]
>>>>> Sent: Friday, April 21, 2017 1:22 PM
>>>>> To: David L Carlson <dcarlson at tamu.edu>; r-help at r-project.org
>>>>> Subject: Re: [R] Looking for a package to replace xtable
>>>>> 
>>>>> David:
>>>>> I tried somethings and got a little more working.
>>>>> Now, I am struck at last line provided: "dec_mean    <-
>>>>> aggregate(Response ~ decc, dd, mean)"
>>>>> Any help is appreciated.
>>>>> Bruce
>>>>> 
>>>>> *****
>>>>> Resp <- data.frame(Response=rbinom(50,1,0.2), yhat=runif(50))
>>>>> Resp <- Resp[order(Response$yhat,decreasing=TRUE),]
>>>>> 
>>>>> ResponseX10    <- do.call(rbind, replicate(10, Resp, simplify=FALSE))
>>>>> str(ResponseX10)
>>>>> 
>>>>> ResponseX10    <- ResponseX10[order(ResponseX10$yhat,decreasing=TRUE),]
>>>>> 
>>>>> str(ResponseX10)
>>>>> head(ResponseX10)
>>>>> 
>>>>> ResponseX10[[2]] <- NULL
>>>>> ResponseX10 <- data.frame(ResponseX10)
>>>>> str(ResponseX10)
>>>>> 
>>>>> cum_R    <- cumsum(Response)
>>>>> cum_R
>>>>> 
>>>>> sam_size <- n
>> 
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list