我有一个0-1的矩阵.我想要做的是循环到这个矩阵并搜索1.每次找到1时,只需跳转或传递该行,以便每行只记录1个值.
如果序列的第一集是1,我想知道的是什么.我在想可能有一个解决方案
break
Run Code Online (Sandbox Code Playgroud)
但我不确定如何正确使用它.
所以这是我的第一个矩阵
SoloNight = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, …Run Code Online (Sandbox Code Playgroud) 我需要逐行折叠数据。
seq = structure(c("h", "d", "s", "s", "f", "k", "s", "s", "f", "d",
"d", "d", "l", "l", "d", "d"), .Dim = c(4L, 4L), .Dimnames = list(
NULL, c("act1.055", "act1.056", "act1.057", "act1.058")))
Run Code Online (Sandbox Code Playgroud)
我的数据如下所示:
act1.055 act1.056 act1.057 act1.058
[1,] "h" "f" "f" "l"
[2,] "d" "k" "d" "l"
[3,] "s" "s" "d" "d"
[4,] "s" "s" "d" "d"
Run Code Online (Sandbox Code Playgroud)
如果我做
paste(seq, collapse = "")
[1] "hdssfkssfdddlldd"
Run Code Online (Sandbox Code Playgroud)
这不是我想要的。
我需要的是
hffl
dkdl
ssdd
ssdd
Run Code Online (Sandbox Code Playgroud)
如果可能,在矩阵中。
一个非常基本的问题.
我无法找到如何在页面中引用或引用帖子.
如果这是我的帖子
---
layout: post
title: "Serve Jekyll Websites with servr and knitr"
categories: [jekyll, rstats]
tags: [knitr, servr, httpuv, websocket]
---
The R package [**servr**](https://github.com/yihui/servr) can be used to set up an HTTP server to serve files under a directory.
Run Code Online (Sandbox Code Playgroud)
我怎么想在我的引用中引用它 page
---
layout: page
title: About
permalink: /about/
---
You can find out more info in this post
Run Code Online (Sandbox Code Playgroud)
你能救我吗?
我无法弄清楚如何用dplyrLong Format数据计算一个简单的平均值.
我的数据如下所示:
hldid idno sex diary age
1 1294 1294_1 2 1 39
2 1294 1294_1 2 2 39
3 1294 1294_2 1 1 43
4 1294 1294_2 1 2 43
...
Run Code Online (Sandbox Code Playgroud)
有4个变量:hldid idno sex diary age
idno是个人标识符,但不是唯一键.
每个人重复2次,每次diary填充一次.
我想要的是简单地计算age平均值sex.
你能救我吗?
我尝试过类似的东西:
dta %>%
group_by(sex) %>%
mutate( ng = n_distinct(idno)) %>%
group_by(age, add=TRUE) %>%
summarise(mean = n()/ng[1] )
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
数据 :
dta = …Run Code Online (Sandbox Code Playgroud) 我想知道如何使用broom包计算置信区间.
我想做的是简单和标准:
set.seed(1)
x <- runif(50)
y <- 2.5 + (3 * x) + rnorm(50, mean = 2.5, sd = 2)
dat <- data.frame(x = x, y = y)
mod <- lm(y ~ x, data = dat)
Run Code Online (Sandbox Code Playgroud)
使用visreg我可以CI非常简单地绘制回归模型:
library(visreg)
visreg(mod, 'x', overlay=TRUE)
Run Code Online (Sandbox Code Playgroud)
我很有兴趣使用broom和重现这个ggplot2,到目前为止我只实现了这个:
library(broom)
dt = lm(y ~ x, data = dat) %>% augment(conf.int = TRUE)
ggplot(data = dt, aes(x, y, colour = y)) +
geom_point() + geom_line(data = dt, …Run Code Online (Sandbox Code Playgroud)