小编bre*_*usn的帖子

RMarkdown: Floating TOC and TOC at beginning

I was wondering if it is possible to have a floating table of contents and another one at the beginning of the document. My current front-matter looks like this:

---
title: "TEST"
author: brettljausn
date: January 15, 2018
output: 
  html_document:
    toc: true
    toc_float:
      toc_collapsed: true
    toc_depth: 3
    number_sections: true
    theme: lumen
---


# Rest of the sample document: --------

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# R Markdown

This is an R Markdown document. Markdown is a simple formatting …
Run Code Online (Sandbox Code Playgroud)

html r knitr r-markdown

16
推荐指数
2
解决办法
2万
查看次数

带有所有x轴值的ggplot x轴标签

我密谋ggplotgeom_point.x轴将是个体ID,y轴是变量A.如何在不重叠标签的情况下在x轴上绘制所有和各个ID值?ID可能不是连续的.

df样本(实际行长得多)

> df
ID     A
1      4
2      12
3      45
5      1
Run Code Online (Sandbox Code Playgroud)

情节代码:

ggplot(df, aes(x = ID, y = A)) + geom_point()
Run Code Online (Sandbox Code Playgroud)

以上代码的间隔为x轴,但不显示个人ID.

谢谢!

axis r ggplot2

10
推荐指数
1
解决办法
3万
查看次数

在已布置的地块之间绘制“网格”

我正在使用4个不同的图,并且正在使用ggpubr软件包中的ggarrange()将它们放在一个图中。我准备了一个例子:

library(ggpubr)
library(ggplot2)

p1 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point() + ggtitle("Plot 1")
p2 <- ggplot(iris, aes(x = Petal.Length, y = Petal.Width)) + geom_point() + ggtitle("Plot 2")
p3 <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Width)) + geom_point() + ggtitle("Plot 3")
p4 <- ggplot(iris, aes(x = Petal.Length, y = Sepal.Width)) + geom_point() + ggtitle("Plot 4") +
  facet_wrap(~Species)

plot.list <- list(p1, p2, p3, p4)

ggarrange(plotlist = plot.list)
Run Code Online (Sandbox Code Playgroud)

输出: 在此处输入图片说明

我想在单个图上画一个边框,如下所示:

在此处输入图片说明

有没有办法画这个边界?谢谢!

r ggplot2 ggpubr

6
推荐指数
2
解决办法
77
查看次数

删除整个数据框中的句点/点

我有一个包含来自世界各地的参与者的大型数据集。其中一些参与者使用点/句号/逗号输入数据来表示千位分隔符,但 R 将它们读取为逗号,这完全扭曲了我的数据......例如 1234 变成 1,234。

我想删除所有点/句号/逗号。我的数据完全由完整数字组成,因此任何地方都不应该有任何小数。

我尝试使用 stringr,但不太明白。这是一个(我希望)可重现的示例,其中包含我的数据的一小部分样本:

structure(
  list(
    chnb = c(10L, 35L, 55L),
    B1_1_77 = c(117.586,
                4022, 4.921),
    C1_1_88 = c(NA, 2206, 1.111),
    C1_1_99 = c(6.172,
                1884, 0),
    C1_3_99 = c(5.62, 129, 0)
  ),
  row.names = c(NA,-3L),
  class = c("tbl_df",
            "tbl", "data.frame")
)
Run Code Online (Sandbox Code Playgroud)

我试过这个:

prob1 <- prob %>% str_replace_all('\\.', '')
Run Code Online (Sandbox Code Playgroud)

这给了我这个:

> prob
[1] "c(10, 35, 55)"         "c(117586, 4022, 4921)" "c(NA, 2206, 1111)"    
[4] "c(6172, 1884, 0)"      "c(562, 129, 0)"  
Run Code Online (Sandbox Code Playgroud)

它确实删除了这些点,但它给了我一个简单的列表,并且完全丢失了我的数据结构。在线搜索建议我这样做:

prob1 <- prob %>% mutate_all(list(str_replace(., '\\.', …
Run Code Online (Sandbox Code Playgroud)

r stringr dplyr

4
推荐指数
1
解决办法
9801
查看次数

如何将 CommunityToolkit.Mvvm 中的源生成器用于 .NET Framework 4.7.2 WPF 应用程序

我最近测试了 WPF UI 库 ( https://wpfui.lepo.co/ )。我创建了一个示例项目,该项目针对 .NET 6.0。示例项目包含一些基本的模型和视图模型,在这些文件中我发现使用[ObservableProperty]属性声明的属性。我真的很喜欢它如何减少简单属性所需的代码量,因此我想将其用于面向 .NET Framework 4.7.2 的现有项目。

但我不知道如何或是否可能。我在网上找到的现有信息非常令人困惑,但这个问题的公认答案听起来是可能的:Roslyn Source Generator not generated any source in a .net Framework 4.7.2

我尝试了以下操作,但应用程序无法构建:

using CommunityToolkit.Mvvm.ComponentModel;

namespace MatlogUtility
{
    public partial class HeatListEntry : ObservableObject
    {
        [ObservableProperty]
        private int? heatListId;

    }
}
Run Code Online (Sandbox Code Playgroud)
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Windows;
using MatlogUtility.Models;


namespace MatlogUtility
{
    public static class SqlQueries
    {
        public static List<HeatListEntry> GetHeatList()
        {
            List<HeatListEntry> heatList = new List<HeatListEntry>();

            string queryString = …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf nuget sourcegenerators

4
推荐指数
2
解决办法
2518
查看次数

根据单独的列计算列中的间隔总和

我有一个df看起来像这样的数据框:

     X1         X2
1     0 0.06174568
2     0 0.06174568
3     0 0.05978832
4     0 0.05978832
5     0 0.06007480
      ...
22    0 0.06082051
23    0 0.06051641
24  128 0.06329613
25    0 0.06099445
26    0 0.06195348
27    0 0.06022723
28    0 0.06041903
29    0 0.06195348
      ...
36    0 0.06195348
37    0 0.06176168
38    0 0.06233710
39  103 0.06195348
40    0 0.06195348
41    0 0.06387155
42    0 0.06291252
Run Code Online (Sandbox Code Playgroud)

我想总结一下值X2,直到X1 != 0,即行1-24和25-39.总和应添加到不同的列中X3:

     X1         X2        X3
1 …
Run Code Online (Sandbox Code Playgroud)

r vectorization dataframe

3
推荐指数
1
解决办法
78
查看次数

dplyr:在变异本身中使用由mutate创建的列

我有一个看起来像这样的数据框:

> df
# A tibble: 5,427 x 3
    cond desired   inc
   <chr>   <dbl> <dbl>
 1  <NA>       0     0
 2  <NA>       5     5
 3     X      10     5
 4     X       7     7
 5  <NA>      16    16
 6  <NA>      21     5
 7  <NA>      26     5
 8  <NA>      31     5
 9     X      37     6
10  <NA>       5     5
Run Code Online (Sandbox Code Playgroud)

这已包括我想要的输出.我想要做的是总结值inc,但如果在前一行Xcond列中有一个,则重置总和.因此,例如在行中,9desired从前一行(31)获取inc-value并从行9(6)中添加-value,这将得到37.而在行中5我只需要使用inc-value因为cond-column前一行是X.我使用循环解决了这个问题,但我想使用矢量化解决方案.到目前为止我得到了这个:

df$test <- …
Run Code Online (Sandbox Code Playgroud)

r dplyr

1
推荐指数
1
解决办法
252
查看次数

标签 统计

r ×6

dplyr ×2

ggplot2 ×2

.net ×1

axis ×1

c# ×1

dataframe ×1

ggpubr ×1

html ×1

knitr ×1

nuget ×1

r-markdown ×1

sourcegenerators ×1

stringr ×1

vectorization ×1

wpf ×1