r

How to convert `c(a,b)` to parameter of `table(a,b)`?

I need to write function vec_to_para,when I run vec_to_para(c('vs','gear'),mtcars),should output result of with(mtcars,table(vs,gear)). I asked a similar quesiton yesterday,then I tried paste() #expected result > with(mtcars,table(vs,gear)) gear vs 3 4 5 0 12 2 4 1 3 10 1 #my function,where is the problem? >vec_to_para<-function(vec,df){ with(df,tables(paste(vec,collapse=','))) } #run to test function >vec_to_para(c('vs','gear'),mtcars) vs,gear 1 Where is the problem of vec_to_para function?

2022-01-25 05:39:25    分类:问答    r

R - (ggplot) Make geom_step jumps dashed

I'm plotting a discrete CDF. I have a few questions regarding geom_step which I'm not finding by using Google. Is it possible to make the line segment representing the jump dashed rather than solid to better show whats going on? Is it possible to add geom_point more efficiently than I do? (less c/p). Below is my current solution: library(tidyverse) library(ggthemes) theme_set(theme_few()) x0 <- seq(-0.5, -0.01, by = 0.01) x1 <- seq(0, 0.99, by = 0.02) x2 <- seq(1, 1.99, by = 0.02) x3 <- seq(2, 2.99, by = 0.02) x35 <- seq(3, 3.49, by = 0.01) x4 <- seq(3.5, 3.99, by = 0.01) tibble_ex <- tibble(

2022-01-25 05:38:48    分类:问答    r   ggplot2

Get size of plot in pixels in R

I am generating a heatmap in R with lots of rows. TL;DR how do I get the real size of a plot in R? df=data.frame(one=1:100,two=101:200,three=201:300) names=1:100 names=paste0("Cell",names) rownames(df)=(names) pheatmap(df,scale="row") default image fits in window, but we can't read row names. pheatmap(df,scale="row",cellheight = 10) changing the cell height lets us read row names but now the image doesn't fit in the window! In this example i am using pheatmap, but also run into this stuff with other plot generating packages. While I've grown to expect frustrating behavior like this from R and

2022-01-25 05:38:32    分类:问答    r   plot   pheatmap

Cumulative aggregates within tidyverse

say I have a tibble (or data.table) which consists of two columns: a <- tibble(id = rep(c("A", "B"), each = 6), val = c(1, 0, 0, 1 ,0,1,0,0,0,1,1,1)) Furthermore I have a function called myfun which takes a numeric vector of arbitrary length as input and returns a single number. For example, you can think of myfun as being the standard deviation. Now I would like to create a third column to my tibble (called result) which contains the outputs of myfun applied to val cumulated and grouped with respect to id. For example, the first entry of result should contain mfun(val). The second entry

2022-01-25 05:28:32    分类:问答    r   dataframe   dplyr   tidyverse   purrr

在 RStudio 中安装 RMarkdown 包在 Windows 7 上不起作用(Installing RMarkdown packages in RStudio does not work on Windows 7)

2022-01-25 05:27:44    分类:技术分享    r   rstudio   r-markdown

A way to not hardcode items in css with R Shiny app?

I have the below code example (taken from here) . Is there a way for the below to work without hardcoding the values "a" and "b" in the html css? If I have hundreds of items I don't want to have to hardcode each one in the call to .option[data-value=a] etc. shinyApp( ui = shinyUI(fluidPage( tags\$head( tags\$style(HTML(" .option[data-value=a], .item[data-value=a]{ background: red !important; color: white !important; } .option[data-value=b], .item[data-value=b]{ background: green !important; color: white !important; } ")) ), sidebarLayout( sidebarPanel( selectizeInput("select", label=NULL

2022-01-25 05:27:40    分类:问答    css   r   shiny   shinyapps

I am running a simulation and need to test the performance of different sized formulas. Drawing from data frame with columns V1, V2, V3... Vk, I need to programmatically create formulas like fit <- ols(y ~ V1 + V2 + V3, data=dataframe) and so forth. How can I code the formula to be able to scale the length of the formula?

2022-01-25 05:27:23    分类:问答    r   regression

如何将 95% 的置信区间添加到 ggplot 中因子水平的比例图？(How to add 95% confidence intervals to graph of proportions of factor levels in ggplot?)

2022-01-25 05:20:49    分类:技术分享    r   ggplot2   errorbar

在管道 %>% 之后插入 if 语句以在自定义函数中返回错误消息(insert if statement after pipe %>% to return error message within custom function)

2022-01-25 05:19:23    分类:技术分享    r   function   if-statement   dplyr   return

如何按组计算日期之间的时间差(how to calculate time difference between dates by group)

2022-01-25 05:18:02    分类:技术分享    r   for-loop   dplyr   purrr   difftime