r

lapply aggregate columns in multiple dataframes R

試著忘記壹切 提交于 2021-02-20 04:16:08
问题 I have several dataframes in a list in R. There are entries in each of those DF I would like to summarise. Im trying to get into lapply so that would be my preferred way (though if theres a better solution I would be happy to know it and why). My Sample data: df1 <- data.frame(Count = c(1,2,3), ID = c("A","A","C")) df2 <- data.frame(Count = c(1,1,2), ID = c("C","B","C")) dfList <- list(df1,df2) > head(dfList) [[1]] Count ID 1 1 A 2 2 A 3 3 C [[2]] Count ID 1 1 C 2 1 B 3 2 C I tried to

Parsing Interview Text

社会主义新天地 提交于 2021-02-20 04:14:07
问题 I have a text file of a presidential debate. Eventually, I want to parse the text into a dataframe where each row is a statement, with one column with the speaker's name and another column with the statement. For example: "Bob Smith: Hi Steve. How are you doing? Steve Brown: Hi Bob. I'm doing well!" Would become: name text 1 Bob Smith Hi Steve. How are you doing? 2 Steve Brown Hi Bob. I'm doing well! Question: How do I split the statements from the names? I tried splitting on the colon: data

Shiny - use column headers from read in file as selectInput choices

a 夏天 提交于 2021-02-20 04:06:25
问题 I'm trying to create an app where people can upload a CSV and then interact with the data. The specific issues is I'm failing to pass the column headers from the file that is read in to the selectInput function. If you comment out the last few lines for the observe function the app works fine. Have tried a number of options, using reactive instead of renderTable etc. There are some similar questions around addressing changing the select input but none that I could see from a file read in.

mapping (ordered) factors to colors in ggplot

有些话、适合烂在心里 提交于 2021-02-20 04:05:55
问题 Consider this example data_frame(mylabel = c('month 18', 'month 19', 'month 20', 'month 21', 'month 22'), value = c(5,10,-2,2,0), time = c(1,2,3,4,5)) %>% ggplot(aes( x= time, y = value, color = mylabel)) + geom_point(size = 7) Here you can see that the variable mylabel has a natural ordering: month 18 comes before month 19 etc. However, this natural ordering is not preserved by the colors chosen by ggplot . In my real dataset, I have about 50 different months and I would like to use a color

mapping (ordered) factors to colors in ggplot

℡╲_俬逩灬. 提交于 2021-02-20 04:05:49
问题 Consider this example data_frame(mylabel = c('month 18', 'month 19', 'month 20', 'month 21', 'month 22'), value = c(5,10,-2,2,0), time = c(1,2,3,4,5)) %>% ggplot(aes( x= time, y = value, color = mylabel)) + geom_point(size = 7) Here you can see that the variable mylabel has a natural ordering: month 18 comes before month 19 etc. However, this natural ordering is not preserved by the colors chosen by ggplot . In my real dataset, I have about 50 different months and I would like to use a color

Shiny - use column headers from read in file as selectInput choices

Deadly 提交于 2021-02-20 04:04:33
问题 I'm trying to create an app where people can upload a CSV and then interact with the data. The specific issues is I'm failing to pass the column headers from the file that is read in to the selectInput function. If you comment out the last few lines for the observe function the app works fine. Have tried a number of options, using reactive instead of renderTable etc. There are some similar questions around addressing changing the select input but none that I could see from a file read in.

mapping (ordered) factors to colors in ggplot

冷暖自知 提交于 2021-02-20 04:04:12
问题 Consider this example data_frame(mylabel = c('month 18', 'month 19', 'month 20', 'month 21', 'month 22'), value = c(5,10,-2,2,0), time = c(1,2,3,4,5)) %>% ggplot(aes( x= time, y = value, color = mylabel)) + geom_point(size = 7) Here you can see that the variable mylabel has a natural ordering: month 18 comes before month 19 etc. However, this natural ordering is not preserved by the colors chosen by ggplot . In my real dataset, I have about 50 different months and I would like to use a color

Placing table next to plot in R Markdown (to pdf / latex)

霸气de小男生 提交于 2021-02-20 03:55:07
问题 Is it possible to place a table generated with the xtable (or alternatively the pander ) package and a generated plot side-by-side in R markdown knitting to pdf while the rest of the document is not in columns? The following simple example hopefully illustrates the idea: \begin{multicols}{2} ```{r} plot(cars) ``` ```{r, results='asis'} library('xtable') print(xtable(head(cars,5)), type = "latex") ``` \end{multicols} However, this does not produce the plot. I know that solutions exist using

Regarding factoring in R

99封情书 提交于 2021-02-20 03:51:43
问题 I have this code where currently I am displaying for 2 patients but I have to group the 3 records and display them for more than 15 patients. Currently I am factoring for each patients as below but is there any way to use factor with grep so that my factor won't become so tedious pat_paste_c<-factor(pat_paste_c,levels=c('Pat_1_IT-6','Pat_1_IT-7','Pat_1_IT-8',"Pat_2_IT-6","Pat_2_IT-7","Pat_2_IT-8"),ordered = TRUE) c<- data.frame(Var=character(), Pat_1=double(), Pat_2=double(), stringsAsFactors

LOCF and NOCF methods for missing data: how to plot data?

淺唱寂寞╮ 提交于 2021-02-20 03:50:21
问题 I'm working on the following dataset and its missing data: # A tibble: 27 x 6 id sex d8 d10 d12 d14 <dbl> <chr> <dbl> <dbl> <dbl> <dbl> 1 1 F 21 20 21.5 23 2 2 F 21 21.5 24 25.5 3 3 NA NA 24 NA 26 4 4 F 23.5 24.5 25 26.5 5 5 F 21.5 23 22.5 23.5 6 6 F 20 21 21 22.5 7 7 F 21.5 22.5 23 25 8 8 F 23 23 23.5 24 9 9 F NA 21 NA 21.5 10 10 F 16.5 19 19 19.5 # ... with 17 more rows I would like to fill the missiningness data via the Last Observation Carried Forward method (LOCF) and the Next