我理解这不是主题,我无法在网上找到任何地方,我想也许社区中的编程大师可能知道这一点.
我经常使用
kill -9 pid
Run Code Online (Sandbox Code Playgroud)
杀了这份工作.我总是想知道9的起源.我在网上查了一下,它说
"9意味着KILL信号不可捕捉或可忽略.换句话说,它会指示进程(某些正在运行的应用程序)立即退出"(来源:http://wiki.answers.com/Q/What_does_kill_-9_do_in_unix_in_its_entirety )
但是,为什么9?那其他数字怎么样?是否有任何历史意义或因为Unix的架构?
我有一个数据框,我想从中删除最后N行.如果我想删除5行,我目前使用以下命令,在我看来这是相当复杂的:
df<- df[-seq(nrow(df),nrow(df)-4),]
Run Code Online (Sandbox Code Playgroud)
你将如何完成任务,是否有一个方便的功能,我可以在R中使用?
在unix中,我会使用:
tac file | sed '1,5d' | tac
Run Code Online (Sandbox Code Playgroud) 使用dplyr,你可以这样做:
iris %>% head %>% mutate(sum=Sepal.Length + Sepal.Width)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species sum
1 5.1 3.5 1.4 0.2 setosa 8.6
2 4.9 3.0 1.4 0.2 setosa 7.9
3 4.7 3.2 1.3 0.2 setosa 7.9
4 4.6 3.1 1.5 0.2 setosa 7.7
5 5.0 3.6 1.4 0.2 setosa 8.6
6 5.4 3.9 1.7 0.4 setosa 9.3
Run Code Online (Sandbox Code Playgroud)
但是上面,我通过列名引用了列.我如何使用1和2哪些列索引来实现相同的结果?
在这里,我有以下内容,但我觉得它并不那么优雅.
iris %>% head %>% mutate(sum=apply(select(.,1,2),1,sum))
Sepal.Length Sepal.Width Petal.Length Petal.Width Species sum
1 5.1 3.5 1.4 0.2 setosa 8.6 …Run Code Online (Sandbox Code Playgroud) 我能够推得很好,但我突然得到这个"致命"的消息
$ git push
fatal: unable to connect to cache daemon: Bad file descriptor
Username for 'https://github.com':
Password for 'https://myid@github.com':
fatal: unable to connect to cache daemon: Bad file descriptor
...
Run Code Online (Sandbox Code Playgroud)
为什么我突然得到这个消息?我该怎么办?
我不确定这可能会有所帮助,但是从现在到此问题发生之前
编码并成功在本地提交更改后,当我尝试将其推送到远程服务器时,我收到以下错误消息
$ git push
致命:无法连接到缓存守护程序:错误的文件描述符'https://github.com'的用户名:'https://myid0@github.com'的密码:致命:无法连接到缓存守护程序:错误的文件描述符致命:松散的物体8ce710b1c78658e066cd2309b12b7766d1be4920(存储在.git/objects/8c/e710b1c78658e066cd2309b12b7766d1be4920中)是致命的致命:远程端挂断意外致命:远程端挂断意外致命:写入错误:文件描述符错误
所以我备份了我所做的所有更改,删除了repo,从github克隆了repo,并对备份文件进行了一些更改,添加,提交和推送更改很好......但是这条消息仍然不会消失:(
我学会了一种非常方便的方法来删除保留订单的重复行,从删除重复项而不排序文件 - BASH.
比如说,如果您有以下文件,
$cat file
a
a
b
b
a
c
Run Code Online (Sandbox Code Playgroud)
您可以使用以下内容删除重复的行:
$awk '!x[$1]++' file
a
b
c
Run Code Online (Sandbox Code Playgroud)
这在运营优先级方面如何运作?
假设我有像这样的RGB值(例如在R中):
cols <- c("#CDE4F3","#E7F3D3","#F7F0C7","#EFCFE5","#D0D1E7")
Run Code Online (Sandbox Code Playgroud)
有没有办法以编程方式派生另一组颜色,这是前者的黑暗版本?
它不一定是R.
浏览源代码时,我看到以下几行:
my @files_to_keep = qw (file1 file2);
my %keep = map { + $_ => 1 } @files_to_keep;
Run Code Online (Sandbox Code Playgroud)
+这段代码片段做了什么?我曾经Data::Dumper看过取出加号是否做了什么,但结果是一样的:
$ perl cleanme.pl
$VAR1 = {
'file1' => 1,
'file2' => 1
};
Run Code Online (Sandbox Code Playgroud) 假设我有一个像这样的变量向量:
>variable
[1] "A1" "A1" "A1" "A1" "A2" "A2" "A2" "A2" "B1" "B1" "B1" "B1"
Run Code Online (Sandbox Code Playgroud)
我想把它转换成这样的数据框:
treatment time
1 A 1
2 A 1
3 A 1
4 A 1
5 A 2
6 A 2
7 A 2
8 A 2
9 B 1
10 B 1
11 B 1
12 B 1
Run Code Online (Sandbox Code Playgroud)
为此,我使用了reshape2的colsplit功能.它需要一个模式来分割字符串,但我很快意识到没有明显的模式来分割两个字符而没有任何空格.我试过""并得到以下结果:
> colsplit(trialm$variable,"",names=c("treatment","time"))
treatment time
1 NA A1
2 NA A1
3 NA A1
4 NA A1
5 NA A2
6 NA A2
7 NA A2 …Run Code Online (Sandbox Code Playgroud) 我想从以下链接下载该文件:
http://www.ncbi.nlm.nih.gov/sviewer/viewer.cgi?tool=portal&sendto=on&log$=seqview&db=nuccore&dopt=gilist&sort=&query_key=1&qty=12654729&filter=all
Run Code Online (Sandbox Code Playgroud)
在网页浏览器(Chrome)中粘贴地址栏中的上述链接时,它允许我将文件另存为"sequence.gi.txt".
但是当我在终端中尝试时,我收到以下错误:
curl -o test.txt http://www.ncbi.nlm.nih.gov/sviewer/viewer.cgi?tool=portal&sendto=on&log$=seqview&db=nuccore&dopt=gilist&sort=&query_key=1&qty=12654729&filter=all
[1] 30036
[2] 30037
[3] 30038
[4] 30039
[5] 30040
[6] 30041
[7] 30042
[8] 30043
-bash: log$=seqview: command not found
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
101 7297 0 7297 0 0 59633 0 --:--:-- --:--:-- --:--:-- 79315
[1] Done curl -L -o test.txt http://www.ncbi.nlm.nih.gov/sviewer/viewer.cgi?tool=portal
[2] Done sendto=on
[3] Exit 127 log$=seqview
[4] Done db=nuccore
[5] Done dopt=gilist
[6] …Run Code Online (Sandbox Code Playgroud) 如何将R代码块逐渐显示?
例如,我在标题中添加了以下选项:
---
...other configurations...
output:
ioslides_presentation:
incremental: true
---
Run Code Online (Sandbox Code Playgroud)
但增量模式仅适用于项目符号,而不适用于代码块
## Slide 1
* this bullet point appears first
* this bullet point appears second
```{r eval=FALSE}
# This chunk is there from the beginning
```
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:你如何在第二颗子弹后出现这个块?