我正在尝试使用名为Math :: Counting的模块:
#!/usr/bin/perl
use strict;
use warnings;
use Math::Counting;
my $f = factorial(3);
print "$f\n";
Run Code Online (Sandbox Code Playgroud)
然而,当我运行它时,我收到以下错误
$ perl UsingModules.pl
Undefined subroutine &main::factorial called at UsingModules.pl line 8.
Run Code Online (Sandbox Code Playgroud)
似乎功能factorial没有被导出,但为什么呢?
当我使用以下内容时
my $f = Math::Counting::factorial(3);
Run Code Online (Sandbox Code Playgroud)
而不是上面的,它完全正常,但我很好奇为什么功能无法导出.
我perl在Cygwin上使用v5.10.1.
这是一个简单的程序.
class Redirection {
public static void main (String args[]){
System.out.println("Hello World_Stdout");
System.err.println("Hello World_Stderr");
}
}
Run Code Online (Sandbox Code Playgroud)
我想在控制台上看到所有输出,但同时我想将stdout和stderr存储在不同的文件中.我尝试了以下命令,但无济于事.
$java Redirection 3>&1 2>stderr 1>stdout 1>&3 2>&3
Run Code Online (Sandbox Code Playgroud)
stderr和stdout文件的文件大小为0.
所以基本上我想做什么"tee"命令,但我也想捕获stderr.
我下载了一个文件,并使用md5sum来查看下载是否成功而没有损坏。我得到以下值:
a7099fcf9572d91b10d0073b07e112cb ./Macaca_mulatta.MMUL_1.70.dna.chromosome.1.fa.gz
Run Code Online (Sandbox Code Playgroud)
但是,当我检查网站时,从中下载了文件,它给了我以下价值。
10256 63747 Macaca_mulatta.MMUL_1.70.dna.chromosome.1.fa.gz
Run Code Online (Sandbox Code Playgroud)
这10位数字是什么?不是md5吗?
我从以下位置下载了文件:ftp : //ftp.ensembl.org/pub/release-70/fasta/macaca_mulatta/dna/CHECKSUMS
在cygwin中,以下代码工作正常
$ cat junk
bat
bat
bat
$ cat junk | sort -k1,1 |tr 'b' 'z' > junk
$ cat junk
zat
zat
zat
Run Code Online (Sandbox Code Playgroud)
但是在linux shell(GNU/Linux)中,似乎覆盖不起作用
[41] othershell: cat junk
cat
cat
cat
[42] othershell: cat junk |sort -k1,1 |tr 'c' 'z'
zat
zat
zat
[43] othershell: cat junk |sort -k1,1 |tr 'c' 'z' > junk
[44] othershell: cat junk
Run Code Online (Sandbox Code Playgroud)
两个环境都运行BASH.
我问这个是因为有时在我进行文本操作之后,由于这个警告,我被迫制作tmp文件.但我知道在Perl中,你可以在执行某些操作/操作后给出"i"标志来覆盖原始文件.我只是想问一下unix管道中是否有任何万无一失的方法来覆盖我不知道的文件.
unix中的以下排序命令有何不同?
1) sort -k1,4 < file
2) sort -k1,1 -k4,4 < file
3) sort -k1,1 -k2,2 -k3,3 -k4,4 < file
Run Code Online (Sandbox Code Playgroud)
特别是,#1和#2令人困惑.例如,以下示例说明了我的观点
$ cat tmp
1 2 3 t
4 2 4 c
5 4 6 c
7 3 20 r
12 3 5 i
2 45 7 a
11 23 53 b
23 43 53 q
11 6 3 c
0 4 3 z
$ diff <(sort -k1,4 tmp) <(sort -k1,1 -k2,2 -k3,3 -k4,4 tmp)
1a2
> 1 2 3 …Run Code Online (Sandbox Code Playgroud) 以下行完美地运作
for(my $i=0; $i < ($max_size - $curr_size) ; $i++){
push (@{$_}, 0);
}
Run Code Online (Sandbox Code Playgroud)
但是这个没有.
push (@{$_}, 0) for (1 .. ($max_size - $curr_size));
Run Code Online (Sandbox Code Playgroud)
它给我一个这样的错误信息:
Can't use string ("1") as an ARRAY ref while "strict refs" in use at coordReadEasy.pl line 124, <DATA> line 16.
Run Code Online (Sandbox Code Playgroud)
为什么?我该怎么解决这个问题?
我在R中使用详细模式(do.trace)运行randomForest,我想知道消息中列的含义是什么.我可以看到ntree树木的数量,OOB是袋子样品的百分比,但是"1"和"2"是什么?
> rf.m <- randomForest(x = X.train, y=as.factor(y.train), do.trace=10)
ntree OOB 1 2
10: 32.03% 15.60% 82.47%
20: 29.18% 10.51% 86.31%
30: 27.44% 7.47% 88.57%
40: 26.48% 5.29% 91.33%
50: 25.92% 4.35% 91.96%
....
Run Code Online (Sandbox Code Playgroud) 在dplyr,如何对所选列执行行向求和(使用列索引)?
这不起作用
> iris %>% mutate(sum=sum(.[1:4])) %>% head
Sepal.Length Sepal.Width Petal.Length Petal.Width Species sum
1 5.1 3.5 1.4 0.2 setosa 2078.7
2 4.9 3.0 1.4 0.2 setosa 2078.7
3 4.7 3.2 1.3 0.2 setosa 2078.7
4 4.6 3.1 1.5 0.2 setosa 2078.7
5 5.0 3.6 1.4 0.2 setosa 2078.7
6 5.4 3.9 1.7 0.4 setosa 2078.7
Run Code Online (Sandbox Code Playgroud)
我可以做到以下几点,但它并不美丽
> iris %>% mutate(index=1:n()) %>%
gather("param", "value", 1:4) %>%
group_by(index) %>%
mutate(sum=sum(value)) %>%
spread(param, value) %>% select(-index)
Source: local data frame …Run Code Online (Sandbox Code Playgroud) 我需要有关如何按照文件方式更改文件格式的建议:
A 504688
B jobnameA
A 504690
B jobnameB
A 504691
B jobnameC
...
Run Code Online (Sandbox Code Playgroud)
到file2:
A B
504688 jobnameA
504690 jobnameB
504691 jobnameC
...
Run Code Online (Sandbox Code Playgroud)
我能想到的一个解决方案是:
cat file1 | perl -0777 -p -e 's/\s+B/\t/' | awk '{print $2"\t"$3}'.
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有更有效的方法或已知的做法来完成这项工作.
为什么以下代码不起作用?
require(dplyr)
`%test%`<- `%>%`
mtcars %test% head
#Error in pipes[[i]] : subscript out of bounds
Run Code Online (Sandbox Code Playgroud)
当以下工作?
a <- function(x) x^2
a(4)
#[1] 16
b <- a
b(4)
#[1] 16
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况,需要做些什么才能使其发挥作用?