我目前有一个名为清算的数据框,我想从中运行 30 个随机样本,每个样本包含 1000 个观察值,指定哪个帐户来自哪个样本,然后将其组合成一个新的数据框,其中包含所有 30 个样本:
这是我在使用 dplyr 包进行随机采样时手动完成的,但希望简化它以实现可重复性:
Sample_1 <- liquidation %>%
sample_n(1000)
Sample_1$Obs <- 1
Sample_2 <- liquidation %>%
sample_n(1000)
Sample_2$Obs <- 2
Sample_3 <- liquidation %>%
sample_n(1000)
Sample_3$Obs <- 3
....
Sample_30 <- liquidation %>%
sample_n(1000)
Sample_30$Obs <- 30
Run Code Online (Sandbox Code Playgroud)
然后我将它们全部组合成一个组合数据框:
Combined <- rbind(Sample_1, Sample_2, Sample_3, Sample_4, Sample_5, Sample_6, Sample_7, Sample_8, Sample_9, Sample_10,
Sample_11, Sample_12, Sample_13, Sample_14, Sample_15, Sample_16, Sample_17, Sample_18, Sample_19,
Sample_20, Sample_21, Sample_22, Sample_23, Sample_24, Sample_25, Sample_26, Sample_27, Sample_28,
Sample_29, Sample_30)
str(Combined)
'data.frame': 30000 obs. …Run Code Online (Sandbox Code Playgroud) 有没有一种有效的方法来获取日期列上的月结束日期。就像如果 date =\xe2\x80\x982023-02-13\xe2\x80\x9d 返回 \xe2\x80\x9c2023-02-28\xe2\x80\x9d 一样,月初也很好。 \n谢谢!
\ndf = pl.DataFrame({'DateColumn': ['2022-02-13']})\n\ntest_df = df.with_columns([\n pl.col('DateColumn').str.strptime(pl.Date).cast(pl.Date)\n]\n)\n\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 DateColumn \xe2\x94\x82\n\xe2\x94\x82 --- \xe2\x94\x82\n\xe2\x94\x82 date \xe2\x94\x82\n\xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1\n\xe2\x94\x82 2022-02-13 \xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\nRun Code Online (Sandbox Code Playgroud)\n两个新的专栏就完美了。
\n我正在尝试在闪亮的数据表中使用 html 标签。我有一个文件,其中通过一些标准文本创建 URL,然后与另一列粘贴在一起以创建完整的 URL。我这里只包含数据和服务器部分。
我还内置了一个过滤器选项,能够过滤其中两列,然后在最后输出数据文件。我有一个简单的可重复示例,说明我想要完成的任务,但我相信我需要添加 escape=FALSE 选项;但我不确定它应该去哪里。所以目前我正在获取格式化的 html,我想要实时 html 并显示 A 列的文本
这是我的数据的简化版本以及我如何尝试设置它。谢谢!
A <- c("Alpha", "Beta", "Gamma", "Delta")
B <- c("one","two","three","four")
C <- c("five","six","seven","eight")
Test_File <- as.data.frame(cbind(A,B,C))
output$table <- DT::renderDataTable(DT::datatable({
data <- Test_File %>%
dplyr::select(A,B) %>%
dplyr::mutate(URL = paste0("https://www.testsite.com/abcdefg/",
A)) %>%
dplyr::mutate(URL = paste0("<a href='", URL, "'>",A,"</a>"))
if(input$a != "All"){
data <- data[data$A == input$a,]
}
if(input$b != "All"){
data <- data[data$B == input$b,]
}
data
}))
Run Code Online (Sandbox Code Playgroud) 我试图在 RMarkdown 中弄清楚如何在某些单词下划线。如果我要编织 HTML,我可以这样做:
<u>These words are underlined</u>
Run Code Online (Sandbox Code Playgroud)
在这种情况下效果很好。但当我在 Microsoft Word 中编织时,下划线不会保留。我不认为对 RMarkdown 进行了任何更改来本地执行此操作,例如粗体和斜体的命令。有什么建议么?
谢谢
我试图在dplyr中进行过滤,其中列就像某些观察一样.我可以使用sqldf作为
Test <- sqldf("select * from database
Where SOURCE LIKE '%ALPHA%'
OR SOURCE LIKE '%BETA%'
OR SOURCE LIKE '%GAMMA%'")
Run Code Online (Sandbox Code Playgroud)
我试图使用以下不会返回任何结果:
database %>% dplyr::filter(SOURCE %like% c('%ALPHA%', '%BETA%', '%GAMMA%'))
Run Code Online (Sandbox Code Playgroud)
谢谢