r

Error: Too few points to calculate an ellipse with 3 points? - R

梦想与她 提交于 2021-02-10 18:36:12
问题 G'day. I am plotting a pca with the factoextra package. I have 3 points for each factor and would like to draw ellipses around each. But I am getting the error Too few points to calculate an ellipse . It is possible to draw ellipses around 3 points in ggplot2 with the stat_ellipse function. I can confirm this by looking at the calculate_ellipse code from ggplot2 that says else if (dfd < 3) {message("Too few points to calculate an ellipse") . So what ellipse function is factoextra using in

evaluate expression in data.table

流过昼夜 提交于 2021-02-10 18:35:16
问题 I'm trying to evaluate a string as a formula: In dplyr it would look like this: dt = data.table(a = 1:10) expr = 'sum(a)' dt %>% mutate(b := !!parse_expr(expr)) However when I try with data.table I'm getting an error: dt[, b := parse_expr(expr)] Error in [.data.table (dt, , := (b, parse_expr(expr))) : RHS of assignment is not NULL, not an an atomic vector (see ?is.atomic) and not a list column. 回答1: Instead of parse_expr , eval(parse can be used dt[, b := eval(parse(text = expr))] Or wrap

evaluate expression in data.table

孤街醉人 提交于 2021-02-10 18:33:36
问题 I'm trying to evaluate a string as a formula: In dplyr it would look like this: dt = data.table(a = 1:10) expr = 'sum(a)' dt %>% mutate(b := !!parse_expr(expr)) However when I try with data.table I'm getting an error: dt[, b := parse_expr(expr)] Error in [.data.table (dt, , := (b, parse_expr(expr))) : RHS of assignment is not NULL, not an an atomic vector (see ?is.atomic) and not a list column. 回答1: Instead of parse_expr , eval(parse can be used dt[, b := eval(parse(text = expr))] Or wrap

Is there a way to create a 3d plot with contours beneath the plot in R?

白昼怎懂夜的黑 提交于 2021-02-10 18:33:11
问题 Is there a way to create a 3d plot in R that has contours beneath the plot like so? If not, is there a way to take my existing contour plot and put it on top of the 3d persp plot? I have been able to make a 3d plot, and a contour plot of the function and constraint, but have not been able to combine the two. Here is my R code: obj = function(x1,x2){ value = -(cos((x1-.1)*x2))^2 - x1*sin(3*x1+x2) return(value) } con1 = function(x1,x2){ t = atan2(x1,x2) value = x1^2 + x2^2 -((2*cos(t)-1/2*cos(2

ggforest function returns error message when used with coxph

强颜欢笑 提交于 2021-02-10 18:31:17
问题 when applying ggforest() to a coxph object I get the follwoing error message error in ggforest(res.cox3, data = Selection_cox) : class(model) == "coxph" are not all TRUE res.cox3 is the output of coxph() which includes a tt term, strata and is of class: > class(res.cox3) [1] "coxph.penal" "coxph" I get the same message for the following dummy data: set.seed(132456) 'dummy survival data' df<-data.frame(id=seq(1,1000,1), event=rep(0,1000),time=floor(runif(1000,7,10)),group=floor(runif(1000,0,2)

R - how to filter data with a list of arguments to produce multiple data frames and graphs

自闭症网瘾萝莉.ら 提交于 2021-02-10 18:30:43
问题 I am looking for a way to use a list of filter arguments to produce different objects. I have a data set for which I want to make several graphs. However, I want all these graphs based on subsets of the dataset. For illustrative purposes I have made the following data. df <- data.frame(type = c("b1", "b2", "b1", "b2"), yield = c("15", "10", "5", "0"), temperature = c("2", "21", "26", "13"), Season = c("Winter", "Summer", "Summer", "Autumn"), profit = c(TRUE, TRUE, FALSE, FALSE)) Also, I have

ggforest function returns error message when used with coxph

前提是你 提交于 2021-02-10 18:29:25
问题 when applying ggforest() to a coxph object I get the follwoing error message error in ggforest(res.cox3, data = Selection_cox) : class(model) == "coxph" are not all TRUE res.cox3 is the output of coxph() which includes a tt term, strata and is of class: > class(res.cox3) [1] "coxph.penal" "coxph" I get the same message for the following dummy data: set.seed(132456) 'dummy survival data' df<-data.frame(id=seq(1,1000,1), event=rep(0,1000),time=floor(runif(1000,7,10)),group=floor(runif(1000,0,2)

Pivot_wider and Group at the same time?

时光怂恿深爱的人放手 提交于 2021-02-10 18:25:19
问题 I have a large data frame that looks like this: Location Dttm Parameter Unit Value 1 Airport 2018-01-01 12:00:00 Wind Direction deg 60 2 Airport 2018-01-01 12:00:00 Wind Speed m/sec 3.45 Obviously there are many more rows that this, I'm just showing an example of the data. I need to pivot the data so there is a column for wind direction and wind speed. But when I run the pivot_wider function I get something like this: Location Dttm Unit Wind Direction Wind Speed 1 Airport 2018-01-01 12:00:00

R scraping with a dropdown menu

做~自己de王妃 提交于 2021-02-10 18:25:05
问题 I am attempting to scrape the NBA daily ROS projections from the site:https://hashtagbasketball.com/fantasy-basketball-projections. Problem is the default number of players selected is 200, I would want 400 (or ALL would work too). This code retrieves the first 200 no problem: > url <- 'https://hashtagbasketball.com/fantasy-basketball-projections' > > page <- read_html(url) > > projs <- html_table(page)[[3]] %>% ### anything after this just cleans the df + rename_all(~gsub('3pm','threes',gsub

R Shiny daterange shows non existent date in data

空扰寡人 提交于 2021-02-10 18:20:37
问题 I have a histogram plot that has dateRangeInput . the code for the menuItem is: menuItem(text = 'Plot', tabName = 'Plots', icon = icon('chart-bar')), conditionalPanel(condition = "input.menu == 'Plots'", dateRangeInput('daterange', 'Enter Start and End Date', start = min(wide_data$SampleTime), end = max(wide_data$SampleTime), min = min(wide_data$SampleTime), max = max(wide_data$SampleTime)), selectInput('UserSelect', 'Select a Vehicle', choices = c('All',unique(wide_data$device_user))),