简体   繁体   中英

Atomic vectors in R and applying function to them

So I have a data set that I'm using from UC Irvine's website("Wine Quality" dataset) and I want to take a look at a plot of the residuals of the data set. The reason I'm doing this is to look to see if there is a an increase in variance so I could run a log based regression. To look at the residuals I apply this code:

residuals(white.wine)

white.wine is how I named my dataframe. However I get this error thrown at me, "NULL" . If I want to look at the residuals of a specific predictor variable like Fixed Acidity I get this error:

Error: $ operator is invalid for atomic vectors.

Any way around this? Thanks for any help!

@Hugh was right in saying that "residuals" must be used against a model, but I think your question was also asking about how to apply something over a data frame. In case you just want the variance of each predictor variable, you might want something like:

apply(white.wine, 2, var)

As the ?apply documentation says, you need to provide the data, the margin , and the function. The margin refers to applying over rows or columns, with 1 signaling to apply a function over the rows, and 2 indicating that the function should be applied over columns. I'm assuming you have predictor variables in columns, so I used a 2 in the code above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM