r

How do i load data set part of the MASS library in R?

孤街醉人 提交于 2021-02-16 07:59:57
问题 I am working through this book dealing with statistical learning/machine learning and R. One of the problem states: To begin, load in the Boston data set. The Boston data set is part of the MASS library in R. library (MASS) Now the data set is contained in the object Boston . Read about the data set: ?Boston I don't understand the syntax library(MASS) . How do I get the Boston data set from this? I've tried Boston=library(MASS) but that gives me an array of words: "MASS" "stats" "graphics"

Formatted latex regression tables with multiple models from broom output?

冷暖自知 提交于 2021-02-16 07:01:33
问题 I have several models such as the example below for which I have estimates, standard errors, p-values, r2 etc. as data.frames in tidy format, but I don't have the original model objects (analysis was run on a different machine). require(broom) model <- lm(mpg ~ hp + cyl, mtcars) tidy_model <- tidy(model) glance_model <- glance(model) # tidy_model # # A tibble: 3 x 5 # term estimate std.error statistic p.value # <chr> <dbl> <dbl> <dbl> <dbl> # 1 (Intercept) 36.9 2.19 16.8 1.62e-16 # 2 hp -0

How do I show all boxplot labels

风流意气都作罢 提交于 2021-02-16 04:21:46
问题 I've created a box plot, the data on the left is the continous variable and the data on the right has about 10 unique options. When I create the boxplot I cannot see the labels. How do I make it show all the labels, possibly vertically? boxplot(data$Rate ~ as.factor(data$Purpose)) I've looked around and cannot work out what im trying to follow. 回答1: You can add argument las=2 to function boxplot() to make all labels perpendicular to axis. df<-data.frame(Rate=rnorm(100),Purpose=rep(letters[1

How do I show all boxplot labels

对着背影说爱祢 提交于 2021-02-16 04:20:26
问题 I've created a box plot, the data on the left is the continous variable and the data on the right has about 10 unique options. When I create the boxplot I cannot see the labels. How do I make it show all the labels, possibly vertically? boxplot(data$Rate ~ as.factor(data$Purpose)) I've looked around and cannot work out what im trying to follow. 回答1: You can add argument las=2 to function boxplot() to make all labels perpendicular to axis. df<-data.frame(Rate=rnorm(100),Purpose=rep(letters[1

Convert “Jan.2008” to date variable

别来无恙 提交于 2021-02-16 04:07:30
问题 How would I convert the following character variables to dates? strDates <- c("Jan.2008", "Feb.2008") str(strDates) chr [1:2] "Jan.2008" "Feb.2008" dates <- as.Date(strDates, "%b %Y") str(dates) Date[1:2], format: NA NA Any assistance would be greatly appreciated 回答1: A Date requires a day element as well, so you can add that to the input string with paste : full.dates <- paste("01", strDates, sep = ".") Specify the template correctly, including separator tokens: as.Date(full.dates, "%d.%b.%Y

Convert “Jan.2008” to date variable

一曲冷凌霜 提交于 2021-02-16 04:04:46
问题 How would I convert the following character variables to dates? strDates <- c("Jan.2008", "Feb.2008") str(strDates) chr [1:2] "Jan.2008" "Feb.2008" dates <- as.Date(strDates, "%b %Y") str(dates) Date[1:2], format: NA NA Any assistance would be greatly appreciated 回答1: A Date requires a day element as well, so you can add that to the input string with paste : full.dates <- paste("01", strDates, sep = ".") Specify the template correctly, including separator tokens: as.Date(full.dates, "%d.%b.%Y

How to reverse point size in ggplot?

巧了我就是萌 提交于 2021-02-15 19:21:06
问题 Please, help me with this point. I need the positive values to be represented as small points and negative as large points. If I tape minus before size, the point sizes are right but the legend is changing: df=data.frame(x=rnorm(20),y=runif(20),z=rnorm(20)) ggplot(df,aes(x=x,y=y))+geom_point(aes(size=-z)) so that does not suite. 回答1: One solution would be to use scale_size() and set your own breaks and then labels in opposite direction. Changed range of z values to get better representation.

How to reverse point size in ggplot?

眉间皱痕 提交于 2021-02-15 19:11:32
问题 Please, help me with this point. I need the positive values to be represented as small points and negative as large points. If I tape minus before size, the point sizes are right but the legend is changing: df=data.frame(x=rnorm(20),y=runif(20),z=rnorm(20)) ggplot(df,aes(x=x,y=y))+geom_point(aes(size=-z)) so that does not suite. 回答1: One solution would be to use scale_size() and set your own breaks and then labels in opposite direction. Changed range of z values to get better representation.

How to reverse point size in ggplot?

前提是你 提交于 2021-02-15 19:10:46
问题 Please, help me with this point. I need the positive values to be represented as small points and negative as large points. If I tape minus before size, the point sizes are right but the legend is changing: df=data.frame(x=rnorm(20),y=runif(20),z=rnorm(20)) ggplot(df,aes(x=x,y=y))+geom_point(aes(size=-z)) so that does not suite. 回答1: One solution would be to use scale_size() and set your own breaks and then labels in opposite direction. Changed range of z values to get better representation.

R group by multiple columns and mean value per each group based on different column

女生的网名这么多〃 提交于 2021-02-15 07:51:44
问题 data set exist data with age, gender, state, income, group . Group represents the group that each user belongs to: group gender state age income 1 3 Female CA 33 $75,000 - $99,999 2 3 Male MA 41 $50,000 - $74,999 3 3 Male KY 32 $35,000 - $49,999 4 2 Female CA 23 $35,000 - $49,999 5 3 Male KY 25 $50,000 - $74,999 6 3 Male MA 21 $75,000 - $99,999 7 3 Female CA 33 $75,000 - $99,999 8 3 Male MA 41 $50,000 - $74,999 9 3 Male KY 32 $35,000 - $49,999 10 2 Female CA 23 $35,000 - $49,999 11 3 Male KY