Sorry to ask ... this is definitely a common question, and this is a silly question, but It is annoying me to assume that I want to get the variance of each numerical column in a data frame, like
df < - data.frame (x = 1: 5, y = seq (1,50,10))) Naturally, I'll try
< Code> var (df) Instead of giving me what I hope, what will happen like this
xy 2.5 250 I get it
xyx 2.5 25 y 25.0 250 which are variations in diagonals, and other places have correlation . Which makes sense when I look at the search (var) and read "var is another interface for the COV", the difference is a convertible and the flow of between yourself, of course. Output is a bit misleading, but I can read with diagonals, or can only generate variants using diag (var (df)) , sapply (df, var) , or repeatedly on lapply (df, var) , or var and df $ x and df $ y Code>. But why? Variance is a regular, basic descriptive figure, which means only second. Should not it be completely and completely trivial to implement in the data frame column? When I was asked only for difference, why should I sympathize? just curious. Thanks for any comments on this.
idiomatic approach
Sapply (df, var) var has a method for data.frames with data.frame By supporting a matrix . variation is a regular basic descriptive figure, so correlation and correlation are they are all interconnected and interesting, especially if you use a linear model Want to You want you to always be able to accomplish your own work
Var & lt; - Function (x, ...) {if (is.data.frame (x)) {Return (sapply (x, var, ...) else {Return (var (x, ...))}}
No comments:
Post a Comment