我想为我的多维结果实现平行坐标.有没有人在matlab或R中实现它的实现?此外,有没有关于用于生成平行坐标的最佳工具的建议?
我有一组1和0.如何计算连续1的最大数量?
(例如,x = [ 1 1 0 0 1 1 0 0 0 1 0 0 1 1 1 ....]
).答案是3,因为连续发生的最大次数是3次.
我正在寻找一些搜索和计数内置功能,但我没有成功.
我有一个数据框,其中列具有重复值,如
employee <- data.frame(name = c('John', 'Joe', 'Mat', 'John', 'Joe'),
salary = c(1500, 2000, 1700, 1210, 2100),
startdate = c('2012-05-10', '2015-02-17',
'2014-09-11', '2011-11-23', '2010-10-27'))
Run Code Online (Sandbox Code Playgroud)
我可以在第1列中获得独特的元素
unique(employee$name)
Run Code Online (Sandbox Code Playgroud)
但是,我想让name
列中的每个项目都是唯一的.如果出现第二次出现_1的话.如果它再次出现_2.因此,在员工数据框中,我想将第二列更改为
John
Joe
Mat
John_1
Joe_1
Run Code Online (Sandbox Code Playgroud)
有没有办法除了循环它?
如何删除包含所有零的文本文件中的行(行)和列.例如,我有一个文件:
1 0 1 0 1
0 0 0 0 0
1 1 1 0 1
0 1 1 0 1
1 1 0 0 0
0 0 0 0 0
0 0 1 0 1
Run Code Online (Sandbox Code Playgroud)
我想删除第2行和第4行以及第2列.输出应如下所示:
1 0 1 1
1 1 1 1
0 1 1 1
1 1 0 0
0 0 1 1
Run Code Online (Sandbox Code Playgroud)
我可以使用sed和egrep来做到这一点
sed '/0 0 0 0/d' or egrep -v '^(0 0 0 0 )$'
Run Code Online (Sandbox Code Playgroud)
对于带有零的行,但对于具有数千列的文件来说太不方便了.我不知道如何删除全部为零的列,第二列.
我正在尝试根据上表中的值格式化DT.例如,我想显示某些内容是否已增加,减少或保持不变.我可以用kable做到这一点,但无法进入下一步我想要克隆一个单元格并在另一个DT中显示与该值相关的所有数据.
library(shiny)
library(DT)
library(dplyr)
ui <- fluidPage(
mainPanel(
dataTableOutput("iris_head")
)
)
server <- function(input, output) {
#df_data <- iris
df_data <- head(iris[-5])
# Just a dataset describing if iris has changed over a month
# If reference data is of the same size as the original data (df_data).
# If reference data is negative I want the cell in the df_data to be green;
# If zero blue and if positive then green.
# I can make changes with ranges …
Run Code Online (Sandbox Code Playgroud) 我rmarkdown
用来生成HTML报告.我在限制机器上,无法安装tex.所以,我试图生成一个HTML文档,然后将其转换/打印为pdf.示例降价文档是:
---
title: "trials"
author: "Foo Bar"
date: "15 December 2016"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r cars, echo=FALSE, cache=FALSE, message=FALSE}
library(dplyr, quietly = TRUE)
library(abind, quietly = TRUE)
virginica <- iris %>% filter(Species == "virginica") %>% head() %>% select(-Species)
setosa <- iris %>% filter(Species == "setosa") %>% head() %>% select(-Species)
diff_mat <- virginica - setosa
diff_mat[diff_mat<0] <- '<font color="green">⇓ </font>'
diff_mat[diff_mat>0] <- '<font color="red">⇑ </font>'
diff_mat[diff_mat == 0] <- '<font color="blue">⇔ </font>' …
Run Code Online (Sandbox Code Playgroud) 我有一堆工作需要在特定的时间间隔执行.但是,我们每天都有足够的资源来完成这项工作.因此,我试图优化开始时间日期(开始时间日期只能向前移动而不是向后移动),这样每天使用的资源与我们预算的资源更不相似.
这些函数在下面的示例中使用::
# Function to shift/rotate a vector
shifter <- function(x, n = 1) {
if (n == 0) x else c(tail(x, -n), head(x, n))
}
# Getting a range of dates
get_date_range <- function(current_date = Sys.Date(), next_planned_date = Sys.Date() + 5)
{
seq.Date(as.Date(current_date), as.Date(next_planned_date), "days")
}
Run Code Online (Sandbox Code Playgroud)
假设玩具示例数据集::此处任务P1在14日开始,而P2从15日开始.值零表示当天没有为该任务完成任务.
# EXAMPLE TOY DATASET
datain = data.frame(dated = c("2018-12-14", "2018-12-15", "2018-12-16", "2018-12-17"),
P1 = c(1,2,0,3), P2 = c(0,4,0,6)) %>%
mutate(dated = as.character(dated))
#The amount of resources that can be used in a …
Run Code Online (Sandbox Code Playgroud) algorithm schedule r mathematical-optimization resource-scheduling
我想删除具有特定字符的文件中的所有行/行,'?' 在我的情况下.我希望在Bash或AWK或Perl中有一个单行命令.谢谢
我有一个标签限制数据读取
1 0 0 1 1 Black Swan
0 0 1 0 0 Golden Duck
1 0 0 1 0 Brown Eagle
0 0 1 0 1 Golden Duck
1 0 0 1 0 Black Swan
1 0 1 0 0 Golden Duck
1 0 0 1 1 Sparrow
Run Code Online (Sandbox Code Playgroud)
最后一列是由空格分隔的一个或多个单词的组合.我想计算最后一列中唯一值的数量,并将其替换为该组唯一的数字.我知道我可以计算并列出使用的数字
awk -F '\t' '{print $NF}' infile | sort | uniq | wc -l
Run Code Online (Sandbox Code Playgroud)
但是如何用数字替换?例如,将所有黑天鹅替换为1,将所有金鸭替换为2等.我希望结果如下:
1 0 0 1 1 1
0 0 1 0 0 2
1 0 0 1 …
Run Code Online (Sandbox Code Playgroud) 我正在使用具有大量条目的a.bib文件.不幸的是,标题中的大写字母不在花括号内.我们可以编写一个简化的脚本来将它们放在花括号中.文件的例子是
@article{foo2002,
author={Foo, A.},
title = {Eating EGGS Daily},
publisher = {ACM},
year={2010}
}
@article{bar2002,
author={Bar, B.},
title = {Going to School},
publisher = {IEEE},
year={1987}
}
@article{alice2012,
author={Alice, C.},
title = {{A} {G}erman in {UK}},
publisher = {ACM},
year={2012}
}
Run Code Online (Sandbox Code Playgroud)
我想更改标题(只有标题而不是其他行),大写字母在大括号内,例如前两种情况下的标题应该是
title = {{E}ating {EGGS} {D}aily},
title = {{G}oing to {S}chool},
Run Code Online (Sandbox Code Playgroud)
但是,如果它们已经在花括号中,我不想更改其他行.所以,第三种情况应该是这样的
title = {{A} {G}erman in {UK}},
Run Code Online (Sandbox Code Playgroud)
我有一个3200行的协作者文件.输出应该是
@article{foo2002,
author={Foo, A.},
title = {{E}ating {EGGS} {D}aily},
publisher = {ACM},
year={2010}
}
@INPROCEEDINGS{bar2002,
author={Bar, B.},
title = {{G}oing to …
Run Code Online (Sandbox Code Playgroud) 我有一个看起来像的文件
No. 1 2 3 4 5
1 1 0 1 0 1
5 0 0 0 0 0
7 1 1 1 0 1
8 0 1 1 0 1
9 1 1 0 0 0
6 0 0 0 0 0
4 0 0 1 0 1
Run Code Online (Sandbox Code Playgroud)
我想附加一个文本,让我们说第一行中所有项目前面的var除了前几个(比方说2,这个数字不同),这样我的文件看起来像
No. 1 var2 var3 var4 var5
1 1 0 1 0 1
5 0 0 0 0 0
7 1 1 1 0 1
8 0 1 1 0 1 …
Run Code Online (Sandbox Code Playgroud) 我有一个数据框,我想找出哪一组变量共享最高的相关性。例如:
mydata <- structure(list(V1 = c(1L, 2L, 5L, 4L, 366L, 65L, 43L, 456L, 876L, 78L, 687L, 378L, 378L, 34L, 53L, 43L),
V2 = c(2L, 2L, 5L, 4L, 366L, 65L, 43L, 456L, 876L, 78L, 687L, 378L, 378L, 34L, 53L, 41L),
V3 = c(10L, 20L, 10L, 20L, 10L, 20L, 1L, 0L, 1L, 2010L,20L, 10L, 10L, 10L, 10L, 10L),
V4 = c(2L, 10L, 31L, 2L, 2L, 5L, 2L, 5L, 1L, 52L, 1L, 2L, 52L, 6L, 2L, 1L),
V5 = c(4L, 10L, 31L, 2L, …
Run Code Online (Sandbox Code Playgroud)