鉴于我现在知道的基本工具(哪个,顺序,如果,%in%,order等等),我经常遇到一个我称之为"唯一性问题"的问题.
问题基本上就像这样......
我有一个矩阵AI想要从另一个原始矩阵B填写.
A:
[upc] [day1] [day2] ... day52
[1] 123 NA NA NA
[2] 456 NA NA NA
[3] 789 NA NA NA
Run Code Online (Sandbox Code Playgroud)
B是巨大的行,所以循环是不可能的.
[upc] [quantity] [day]
[1] 123 11 1
[2] 123 2 1
[3] 789 5 1
[4] 456 10 1
[5] 789 6 1
Run Code Online (Sandbox Code Playgroud)
我想用矩阵A中的每个UPC填充day1,矩阵B中的数量.问题是B中每个UPC有多个实例,我不能循环它们以获得放在旁边的总数量每个upc.
所以我想要的是这个...(这将完全填写,即2-52天...在其他日子循环,这是小的,因此可管理)
A:
[upc] [day1] [day2] ... day52
[1] 123 13 NA NA
[2] 456 10 NA NA
[3] 789 11 NA NA
Run Code Online (Sandbox Code Playgroud)
你知道任何可以在没有循环的情况下实现这一目标的函数吗
我需要在numpy数组中存储大量信息.它需要具有以下形状:
facefeature1s = np.empty([2000,64,64,64,32])
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到一个内存错误.我该怎么办?
错误是:
MemoryError Traceback (most recent call last)
<ipython-input-271-2c56a37b4a7c> in <module>()
----> 1 facefeature1s = np.empty([2000,64,64,64,32])
Run Code Online (Sandbox Code Playgroud) 我正在尝试将pandas df写入csv.但是,我需要循环很多才能以块的形式获取输出.我想在csv中垂直堆叠输出.因此,在每次迭代之后,我想写一组特定的行(1:10,然后是11:20,等等......)并清除内存,以免制作一个巨大的物体.是否可以使用df.to_csv来执行此操作?
大熊猫中的直方图绘制每个箱的计数,而不是标准化的分数.在R中,这是直方图中的一个选项.熊猫可以吗?如果没有,任何建议的简单解决方法?
我的问题与我之前的问题有关.
假设我有一个矩阵和4个向量(可以考虑另一个矩阵,因为向量的顺序很重要),我想按顺序得到与每个向量重合的行号.我希望解决方案避免重复向量并尽可能高效,因为问题是大规模的.
例.
set.seed(1)
M = matrix(rpois(50,5),5,10)
v1 = c(3, 2, 7, 7, 4, 4, 7, 4, 5, 6)
v2= c(8, 6, 4, 4, 3, 8, 3, 6, 5, 6)
v3= c(4, 8, 3, 5, 9, 4, 5, 6, 7 ,7)
v4= c(4, 9, 3, 6, 3, 1, 5, 7,6, 1)
Vmat = cbind(v1,v2,v3,v4)
M
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 4 8 3 5 9 4 5 6 7 7
[2,] 4 …Run Code Online (Sandbox Code Playgroud) library(stargazer)
stargazer(mtcars)
Run Code Online (Sandbox Code Playgroud)
我想省略表设置部分,而不是:
% Table created by StarGazer v.3.0.1 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Thu, May 09, 2013 - 16:14:28
\begin{table}[htb] \centering
\caption{}
\label{}
\footnotesize
\begin{tabular}{@{\extracolsep{5pt}}l c c c c c }
\\[-1.8ex]\hline
\hline \\[-1.8ex]
Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\
\hline \\[-1.8ex]
mpg & 32 & 20.091 & 6.027 & 10.400 & 33.900 \\
cyl & 32 & 6.188 & 1.786 & 4 & …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用具有多个相当动态条件的数据表进行内部联接。我被语法绊倒了。首先,我创建两个对象,x并且x2要对其进行内部联接。
set.seed(1)
#generate data
x = data.table(CJ(t=1:10, d=1:3,p1s=seq(1,3,by=0.1),p1sLAST=seq(1,3,by=0.1)))
x[d==1,p1sLAST:=3]
x=x[p1s<=p1sLAST]
x2 = data.table(CJ(tprime=1:10, p1sLASTprm=seq(1,3,by=0.1)))
Run Code Online (Sandbox Code Playgroud)
与对象:
> x
t d p1s p1sLAST
1: 1 1 1.0 3.0
2: 1 1 1.0 3.0
3: 1 1 1.0 3.0
4: 1 1 1.0 3.0
5: 1 1 1.0 3.0
---
9026: 10 3 2.8 2.9
9027: 10 3 2.8 3.0
9028: 10 3 2.9 2.9
9029: 10 3 2.9 3.0
9030: 10 3 3.0 3.0
> x2
tprime p1sLASTprm …Run Code Online (Sandbox Code Playgroud) 我有一个如下所示的数据框:
weekyear Location_Id priceA priceB
1 20101 6367 0.8712934 8
2 20101 6380 0.1712934 8
3 20102 6367 0.8712934 4
4 20102 6380 0.4712934 4
5 20103 6367 0.8712934 1
6 20103 6380 0.8712934 9
Run Code Online (Sandbox Code Playgroud)
我想贬低priceA和priceB.每个都按位置和时间索引.我想要的
priceAnew = priceA_{location,time} - mean(over time)(priceA_{location}) - mean(over location)(priceA_{time})
Run Code Online (Sandbox Code Playgroud)
这里的符号更清晰:https: //stats.stackexchange.com/questions/126549/do-people-used-fixed-effects-in-lasso
这是一种无益的方式吗?
当我尝试将Rmarkdown文档编译为pdf时,出现以下错误:
Error: Functions that produce HTML output found in document targeting latex output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:
always_allow_html: yes
Note however that the HTML output will not be visible in non-HTML formats.
Run Code Online (Sandbox Code Playgroud)
有人知道这意味着什么吗?
我想比较R中数据表中的多个列,我不想对它们进行硬编码.例如,请参阅下面的简单示例:
###########
#Setup data
###########
set.seed(2)
fill = data.table(n=1:7)
Tp=3
for(t in 1:Tp){
set(x = fill, j = paste0('v',t), value = sample(0:10,7))
}
fill[1,paste0('v',3):=0]
fill[5,paste0('v',2):=0]
fill[5,paste0('v',3):=0]
for(t in 1:Tp){
fill[,paste0('v',t,'prm'):=get(paste0('v',t))]
}
fill[1,paste0('v',1,'prm'):=0]
fill[2,paste0('v',2,'prm'):=1]
fill[5,paste0('v',3,'prm'):=1]
fill[7,paste0('v',3,'prm'):=2]
Run Code Online (Sandbox Code Playgroud)
所以数据是:
> fill
n v1 v2 v3 v1prm v2prm v3prm
1: 1 2 9 0 0 9 0
2: 2 7 4 8 7 1 8
3: 3 5 10 9 5 10 9
4: 4 1 8 1 1 8 1
5: 5 6 …Run Code Online (Sandbox Code Playgroud)