[R] Injecting a column of characters to a matrix of numerics

Steven Yen syen04 at gmail.com
Wed Oct 29 16:58:52 CET 2014


Wonderful. Works great!
Steven Yen

At 11:52 AM 10/29/2014, Kevin E. Thorpe wrote:
>On 10/29/2014 11:41 AM, Steven Yen wrote:
>>Hello
>>I am designing a regression printout, which works out nicely. Then, I
>>try to inject a column of characters to indicate a discrete regressor
>>with a dot (.). Then, all numbers seem to turn into characters, in
>>quotations. Is there a way to do this right? Below, I show the lines of
>>codes before and after. Thanks.
>>Steven Yen
>>
>>---
>>out<-round(cbind(me,se,t,p),digits)
>>colnames(out)<-c("estimates","s.e.","|t-value|","p-value")
>>rownames(out)<-rownames(me)
>>out
>>              estimates     s.e. |t-value|  p-value
>>(Intercept)  0.223263 0.146167  1.527459 0.127173
>>sex          0.049830 0.039612  1.257973 0.208890
>>age         -0.070423 0.029539  2.384035 0.017433
>>yrmarry      0.015567 0.005298  2.938126 0.003429
>>children     0.060525 0.044778  1.351659 0.176993
>>religius    -0.053128 0.014413  3.686260 0.000248
>>educ         0.003226 0.008453  0.381636 0.702866
>>occu         0.003915 0.011860  0.330147 0.741404
>>rating      -0.077856 0.014466  5.381925 0.000000
>>
>>out<-round(cbind(me,se,t,p),digits); out<-cbind(out,disc)
>>colnames(out)<-c("estimates","s.e.","|t-value|","p-value","disc")
>>rownames(out)<-rownames(me)
>>
>>(Intercept) "0.223263"  "0.146167" "1.527459" "0.127173" ""
>>sex         "0.04983"   "0.039612" "1.257973" "0.20889"  "."
>>age         "-0.070423" "0.029539" "2.384035" "0.017433" ""
>>yrmarry     "0.015567"  "0.005298" "2.938126" "0.003429" ""
>>children    "0.060525"  "0.044778" "1.351659" "0.176993" "."
>>religius    "-0.053128" "0.014413" "3.68626"  "0.000248" ""
>>educ        "0.003226"  "0.008453" "0.381636" "0.702866" ""
>>occu        "0.003915"  "0.01186"  "0.330147" "0.741404" ""
>>rating      "-0.077856" "0.014466" "5.381925" "0"        ""
>
>Use data frames instead.
>
>out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,disc)
>names(out)<-c("estimates","s.e.","|t-value|","p-value","disc")
>
>>______________________________________________
>>R-help at r-project.org mailing list
>>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.
>
>
>--
>Kevin E. Thorpe
>Head of Biostatistics,  Applied Health Research Centre (AHRC)
>Li Ka Shing Knowledge Institute of St. Michael's
>Assistant Professor, Dalla Lana School of Public Health
>University of Toronto
>email: kevin.thorpe at utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016



More information about the R-help mailing list