Tutorial :R Question. Numeric variable vs. Non-numeric and â€œnamesâ€ function Question:

`` > scores=cbind(UNCA.score, A.score, B.score, U.m.A, U.m.B)     > names(scores)=c('UNCA.scores', 'A.scores', 'B.scores','UNCA.minus.A', 'UNCA.minus.B')     > names(scores)    "UNCA.scores"  "A.scores"     "B.scores"     "UNCA.minus.A" "UNCA.minus.B"     > summary(UNCA.scores)    X6.69230769230769    Min.   : 4.154       1st Qu.: 7.333       Median : 8.308       Mean   : 8.451       3rd Qu.: 9.538       Max.   :12.000       > is.numeric(UNCA.scores)    FALSE    > is.numeric(scores[,1])    TRUE  ``

My question is, what is the difference between UNCA.scores and scores[,1]? UNCA.scores is the first column in the data.frame 'scores', but they are not the same thing, since one is numeric and the other isn't.

If UNCA.scores is just a label here how can I make it be equivalent to 'scores[,1]?

Thanks!

Solution:1

`scores` is a matrix, not a data.frame. Use `data.frame` to create a data.frame, not `cbind`.

All columns in a matrix are of the same type, and in this case using `cbind` coerces all elements to numeric.

Solution:2

It seems like there's something funny with the code you posted. If there isn't already an object called UCNA.scores when your code begins, trying to pass it to the summary function should produce an error, because you can't just refer to a matrix column by name. Another thing is that assigning names to a matrix names the elements, not the columns. Your output is what I would expect if you made scores a data.frame and attached it right after creating it.

Even with these things aside, I can't reproduce your problem. Could you post some example data and/or show anything else going on if there really are parts missing?

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »