r

R - dealing with new aliased coefficient (“NA” coefficient) in categorical variables for VIF

陌路散爱 提交于 2021-02-11 15:14:04
问题 Currently, I want to check multi-collinearity among different categorical variables. FYI, I'm using 2 independent variables - category and division , and 1 independent variable - resolution_time_second as an example here. First, the error message below occurred to me when I tried to perform VIF - Variance Inflation Factor (using R car::vif ) on the glm() model. Error in vif.default(fit) : there are aliased coefficients in the model Then, I found out that I have encountered into so-called

R append dataframe name to each of its columns within a list of dataframes

雨燕双飞 提交于 2021-02-11 15:13:53
问题 I want to append the dataframe-name to each of its columns in the following list of dataframes: df1 <- tibble(V1=c(1, 1, 3, 1), V2=c(2, 1, 2, 2), V3=c(4, 1, 1, 2)) df2 <- tibble(V1=c(1, 1, 3, 1), V2=c(2, 1, 2, 2), V3=c(4, 1, 1, 2)) df <- list(df1, df2) names(df) <- c("df1", "df2") df This is how I would like it to look: $df1 # A tibble: 4 x 3 df1_V1 df1_V2 df1_V3 <dbl> <dbl> <dbl> 1 1 2 4 2 1 1 1 3 3 2 1 4 1 2 2 $df2 # A tibble: 4 x 3 df2_V1 df2_V2 df2_V3 <dbl> <dbl> <dbl> 1 1 2 4 2 1 1 1 3 3

R append dataframe name to each of its columns within a list of dataframes

耗尽温柔 提交于 2021-02-11 15:12:25
问题 I want to append the dataframe-name to each of its columns in the following list of dataframes: df1 <- tibble(V1=c(1, 1, 3, 1), V2=c(2, 1, 2, 2), V3=c(4, 1, 1, 2)) df2 <- tibble(V1=c(1, 1, 3, 1), V2=c(2, 1, 2, 2), V3=c(4, 1, 1, 2)) df <- list(df1, df2) names(df) <- c("df1", "df2") df This is how I would like it to look: $df1 # A tibble: 4 x 3 df1_V1 df1_V2 df1_V3 <dbl> <dbl> <dbl> 1 1 2 4 2 1 1 1 3 3 2 1 4 1 2 2 $df2 # A tibble: 4 x 3 df2_V1 df2_V2 df2_V3 <dbl> <dbl> <dbl> 1 1 2 4 2 1 1 1 3 3

how to identify the columns that are same but in different order or one within another one?

徘徊边缘 提交于 2021-02-11 15:06:28
问题 I have a dataset that capture a list of data's variables. It looks like this: It can be build using codes: df<-structure(list(cxr.CSV = c("project", "Subject", "Site", "InstanceName", "RecordPosition", "CXRDT", "CXRFIND", "CXRFNDSP", "CXRYN", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), cy1.CSV = c("project", "Subject", "Site", "InstanceName", "RecordPosition", "CYSHPYN", "CYSHPDT", "CY1TMPT", "CYND", "CYNDSP", "CYDT", "CYTM"

how to identify the columns that are same but in different order or one within another one?

戏子无情 提交于 2021-02-11 15:06:23
问题 I have a dataset that capture a list of data's variables. It looks like this: It can be build using codes: df<-structure(list(cxr.CSV = c("project", "Subject", "Site", "InstanceName", "RecordPosition", "CXRDT", "CXRFIND", "CXRFNDSP", "CXRYN", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), cy1.CSV = c("project", "Subject", "Site", "InstanceName", "RecordPosition", "CYSHPYN", "CYSHPDT", "CY1TMPT", "CYND", "CYNDSP", "CYDT", "CYTM"

ggplot not properly displaying

て烟熏妆下的殇ゞ 提交于 2021-02-11 15:02:33
问题 I currently am trying to graph 2 columns in a data frame I created using ggplot I am graphing date vs. numeric value. I used dplyr library to create the dataframe: is_china <- confirmed_cases_worldwide %>% filter(country == "China", type=='confirmed') %>% mutate(cumu_cases = cumsum(cases)) I believe the reason is due to the y value being a result column of cumsum function, but am unsure The table looks something like this, the last column being the targeted y value: 2020-01-22 NA China 31

downloadButton to download multiple renderPlot reactive in shiny server

跟風遠走 提交于 2021-02-11 14:57:30
问题 I am creating a shiny application that displays several graphics. And I will like through a button download, download all graphs display I do the following: server = function(input, output) { df<-data.frame(q=c(1,3,5,7,9),w=c(2,4,6,8,10),z=c(1,2,3,4,5)) # output all plot output$p1 <- renderPlot({ ggplot(df,aes(x=q,y=w)) + geom_point() }) output$p2 <- renderPlot({ ggplot(df,aes(x=z,y=w))+geom_point() }) output$p3 <- renderPlot({ ggplot(df,aes(x=q,y=z))+geom_point() }) # Here is my function to

verticaly center table grobs in rmarkdown pdf

試著忘記壹切 提交于 2021-02-11 14:54:59
问题 I want to have my table grobs aligned to the top of each other but verticaly centered to the page with respect to the longest table. I need this to be automatic with tables of different lengths. This is what I have to vertically align them with each other as shown by @baptiste here. --- output: pdf_document geometry: - paperwidth=13.333in - paperheight=7.5in - margin=.5in --- ```{r, echo=F, fig.align='center'} library(magrittr) library(gridExtra) library(gtable) library(grid) # from https:/

Population pyramid in ggplot

对着背影说爱祢 提交于 2021-02-11 14:53:29
问题 I've read a related post (Simpler population pyramid in ggplot2), but I have a slightly different setup which results in a messed-up pyramid. Make the test data frame: test <- data.frame(cbind(c(replicate(3,"population 1"), replicate(3,"population 2")),c("top","middle","bottom","top","middle","bottom"),c(70,25,5,82,13,3))) Fix the factor ordering: levels(test$X3) [1] "13" "25" "3" "5" "70" "82" test$X3 <- factor(test$X3, levels=c(70,25,5,82,13,3)) levels(test$X2) [1] "Bottom" "Middle" "Top"

Population pyramid in ggplot

对着背影说爱祢 提交于 2021-02-11 14:50:10
问题 I've read a related post (Simpler population pyramid in ggplot2), but I have a slightly different setup which results in a messed-up pyramid. Make the test data frame: test <- data.frame(cbind(c(replicate(3,"population 1"), replicate(3,"population 2")),c("top","middle","bottom","top","middle","bottom"),c(70,25,5,82,13,3))) Fix the factor ordering: levels(test$X3) [1] "13" "25" "3" "5" "70" "82" test$X3 <- factor(test$X3, levels=c(70,25,5,82,13,3)) levels(test$X2) [1] "Bottom" "Middle" "Top"