给出两个向量:
x <- rnorm(10, 10, 1)
y <- rnorm(10, 5, 5)
Run Code Online (Sandbox Code Playgroud)
如何计算科恩的效果大小?
例如,我想使用pwr包来估计具有不等方差的t检验的功效,并且它需要Cohen的d.
require('fortunes')
fortune('106')
Personally I have never regretted trying not to underestimate my own future stupidity.
-- Greg Snow (explaining why eval(parse(...)) is often suboptimal, answering a question triggered
by the infamous fortune(106))
R-help (January 2007)
Run Code Online (Sandbox Code Playgroud)
那么,如果eval(parse(...))不是最理想,另一种方法是什么呢?
我使用RCurl从网站调用一些数据,我fromJSON()在rjson包中使用后得到的是列表中的列表.部分列表具有将根据订单更改的订单号的名称.该列表看起来像:
$orders
$orders$'5810584'
$orders$'5810584'$quantity
[1] 10
$orders$'5810584'$price
[1] 15848
Run Code Online (Sandbox Code Playgroud)
我想提取值 $orders$'5810584'$price
假设列表在对象中dat.我使用的方法eval(parse(...))是:
or_ID <- names(dat$orders) # get the order ID number
or_ID
"5810584"
sell_price <- eval(parse(text=paste('dat$',"orders$","'", or_ID, "'", "$price", sep="")))
sell_price
15848
Run Code Online (Sandbox Code Playgroud)
这样做的最佳方式是什么?
我试图在R中制作一个情节,其中一部分情节是灰色的,以强调这个区域.与其他示例不同,我不想为绘图下的区域着色,而是在绘图上从一个区域开始并到达图形末尾的区域.当我尝试使用rect()或polygon()时,它会模糊我想强调的图.
例如:
x_mean <- c(1, 2, 3, 4)
y_mean <- c(1, 1, 1, 1)
y_max <- c(4, 4, 4, 4)
y_min <- c(-4, -4, -4, -4)
x_shade <- c(2, 3, 4)
y_max_shade <- c(4, 4, 4)
y_min_shade <- c(-4, -4, -4)
plot(x=rep(x_mean, 3), y=c(y_mean, y_max, y_min), bty='n', type="n" )
arrows(x0=x_mean, y0=y_min, x1=x_mean, y1=y_max, length=0)
points( x=x_mean, y=y_mean, pch=16)
Run Code Online (Sandbox Code Playgroud)
这将在图表上绘制4条线.如何在背景中从第2行到结束绘制灰色框?
这看起来应该是常见的事情,但我所有的搜索都会提出一半或未完成的答案.
我在csv中有一组数据.但是数据的设置是时间,价格,数量.为了正确分析我的数据,我需要OHLCV格式:开放,高,低,关闭,音量.
有谁知道如何重新格式化为OHLCV?
以下是数据集的示例:
time,price,volume,
7/18/10 0:09,0.04951,20,
7/18/10 4:43,0.05941,50.01,
7/18/10 18:48,0.0808,5,
7/18/10 22:44,0.08585,10,
7/18/10 23:00,0.08584,5,
7/18/10 23:00,0.08584,5,
7/19/10 4:53,0.0909,5,
7/19/10 17:24,0.09307,80,
7/19/10 18:03,0.08911,100,
7/19/10 18:07,0.08752,100,
7/19/10 18:12,0.09109,90,
7/19/10 21:44,0.08416,20,
7/19/10 21:55,0.07921,100,
7/19/10 21:56,0.07921,10,
7/19/10 21:57,0.07723,20,
7/19/10 22:02,0.0808,49
7/20/10 3:36,0.08181,100
7/20/10 4:54,0.0818,12
7/20/10 13:48,0.08119,4
7/20/10 13:50,0.07921,10
7/20/10 15:37,0.07822,10
7/20/10 15:39,0.07723,10
7/20/10 16:01,0.07624,10
7/20/10 18:08,0.07723,10
7/20/10 18:09,0.07723,10
7/20/10 18:09,0.07723,20
7/20/10 21:09,0.07426,4.5
7/20/10 21:38,0.07426,5.5
7/20/10 21:38,0.07426,4.5
7/20/10 21:41,0.07426,45.5
7/20/10 22:24,0.07472,3
7/20/10 22:28,0.07472,1
7/20/10 22:29,0.07474,1
7/20/10 22:29,0.07474,1
7/21/10 3:27,0.07425,60
7/21/10 3:30,0.07327,10
7/21/10 …Run Code Online (Sandbox Code Playgroud) 仅供参考:自从我的第一版以来,我对此进行了大量编辑.这种模拟已经从14小时减少到14分钟.
我是编程的新手,但我做了一个模拟试图遵循有机体中的无性复制并量化母体和子体生物之间染色体数量的差异.模拟运行速度非常慢.完成大约需要6个小时.我想知道什么是使模拟运行更快的最佳方法.
这些数字生物有x个染色体.与大多数生物体不同,染色体彼此独立,因此它们具有转移到子体生物体中的相同机会.
在这种情况下,染色体进入子细胞的分布遵循二项分布,概率为0.5.
该函数sim_repo采用具有已知数量染色体的数字生物矩阵,并使它们经历12代复制.它复制这些染色体,然后使用该rbinom函数随机生成一个数字.然后将该数字分配给子单元格.由于在无性繁殖期间没有染色体丢失,另一个子细胞接收剩余的染色体.然后对G代进行重复.然后从矩阵中的每一行采样单个值.
sim_repo = function( x1, G=12, k=1, t=25, h=1000 ) {
# x1 is the list of copy numbers for a somatic chromosome
# G is the number of generations, default is 12
# k is the transfer size, default is 1
# t is the number of transfers, default is 25
# h is the number of times to replicate, default is 1000
dup <- x1 * 2 # …Run Code Online (Sandbox Code Playgroud) 我在R中有一个矩阵,我想从每一行中取一个随机样本.我的一些数据是在NA中,但在采用随机样本时,我不希望NA作为采样的选项.我怎么做到这一点?
例如,
a <- matrix (c(rep(5, 10), rep(10, 10), rep(NA, 5)), ncol=5, nrow=5)
a
[,1] [,2] [,3] [,4] [,5]
[1,] 5 5 10 10 NA
[2,] 5 5 10 10 NA
[3,] 5 5 10 10 NA
[4,] 5 5 10 10 NA
[5,] 5 5 10 10 NA
Run Code Online (Sandbox Code Playgroud)
当我将样本函数应用于此矩阵以输出另一个矩阵时,我得到了
b <- matrix(apply(a, 1, sample, size=1), ncol=1)
b
[,1]
[1,] NA
[2,] NA
[3,] 10
[4,] 10
[5,] 5
Run Code Online (Sandbox Code Playgroud)
相反,我不希望NA能够作为输出,并希望输出类似于:
b
[,1]
[1,] 10
[2,] 10
[3,] 10
[4,] 5 …Run Code Online (Sandbox Code Playgroud) 我在删除xts对象中的重复行时遇到问题.我有一个R脚本,它将下载货币的刻度财务数据并将其转换为OHLC格式的xts对象.该脚本还每15分钟提取一次新数据.新数据从今天的第一笔交易下载到今天的最后一笔交易.下载的旧旧数据以.Rdata格式存储并调用.然后将新数据添加到旧数据中,并以.Rdata格式覆盖旧数据.
以下是我的数据的示例:
.Open .High .Low .Close .Volume .Adjusted
2012-01-07 00:00:11 6.69683 7.01556 6.38000 6.81000 48387.58 6.81000
2012-01-08 00:00:09 6.78660 7.20000 6.73357 7.11358 57193.53 7.11358
2012-01-09 00:00:57 7.08362 7.19100 5.81000 6.32570 148406.85 6.32570
2012-01-10 00:01:01 6.32687 6.89000 6.00100 6.36000 110210.25 6.36000
2012-01-11 00:00:07 6.44904 7.13800 6.41266 6.90000 99442.07 6.90000
2012-01-12 00:01:02 6.90000 6.99700 6.33700 6.79999 140116.52 6.79999
2012-01-13 00:02:01 6.78211 6.80400 6.40000 6.41000 60228.77 6.41000
2012-01-14 00:00:23 6.42000 6.50000 6.23150 6.31894 25392.98 6.31894
Run Code Online (Sandbox Code Playgroud)
现在如果我再次运行脚本,我会将新数据添加到xts.
.Open .High .Low .Close .Volume .Adjusted
2012-01-07 …Run Code Online (Sandbox Code Playgroud) 在讨论如何使用Bio.SeqIO.parse()导入序列数据时,BioPython食谱说明:
有一个可选的参数字母表来指定要使用的字母表.这对于像FASTA这样的文件格式很有用,否则Bio.SeqIO将默认为通用字母表.
如何添加此可选参数?我有以下代码:
from os.path import abspath
from Bio import SeqIO
handle = open(f_path, "rU")
records = list(SeqIO.parse(handle, "fasta"))
handle.close()
Run Code Online (Sandbox Code Playgroud)
这将从UniProt数据库导入大量FASTA文件.问题是它在通用的SingleLetterAlphabet类中.如何在SingleLetterAlphabet和ExtendedIUPACProtein之间进行转换?
最终目标是在这些序列中搜索诸如GxxxG之类的主题.
多年来我一直在学习计算机编程,抽象层使我的理解变得模糊。假设我编译了一些源代码并且我有可执行的机器代码。一旦计算机运行此代码,会发生什么?
例如,假设我运行一个简单的 if then else 语句并拥有机器代码。执行此指令的计算机电路中发生了什么?
我正在尝试使用RCurl以json格式获取一些数据.
我必须使用POST输入用户名和密码,例如:
postForm(url1, user=x$USERNAME, pass=x$PASSWORD)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error in function (type, msg, asError = TRUE) :
Run Code Online (Sandbox Code Playgroud)
SSL读取:错误:00000000:lib(0):func(0):reason(0),errno 54
如果我从libcurl站点研究了正确的错误号54 :
CURLE_SSL_ENGINE_SETFAILED(54)
将所选SSL加密引擎设置为默认值失败!
如果这是正确的错误,我将如何选择SSL引擎?
duplicated()给出TRUE或FALSE声明取决于该位置先前是否在向量中重复.如果我不仅要删除重复的位置,而且还要删除它重复的所有先前位置,该怎么办?
a <- c("A", "B", "C")
b <- c("A", "B", "C", "D")
Run Code Online (Sandbox Code Playgroud)
a包含将要复制的所有值,并b包含a未复制的值和一些其他值.
我怎么才提取"D"?