如何使用RStudio中的devtools在github上创建新的存储库?我试过:
然后我想我会create("MyNewRPackage")用来初始化目录结构和README.md文件.但是包骨架被创建为我项目的子文件夹而且我有~/MyNewRPackage/MyNewRPackage/R.但我需要在我的github存储库的根文件夹中创建包骨架.
使用devtools和RStudio在github上开始新R包开发的标准方法是什么?
我想在表中导入很多XML文件xml_data:
create table xml_data(result xml);
Run Code Online (Sandbox Code Playgroud)
为此,我有一个带循环的简单bash脚本:
#!/bin/sh
FILES=/folder/with/xml/files/*.xml
for f in $FILES
do
psql psql -d mydb -h myhost -U usr -c \'\copy xml_data from $f \'
done
Run Code Online (Sandbox Code Playgroud)
但是,这将尝试将每个文件的每一行导入为单独的行.这会导致错误:
ERROR: invalid XML content
CONTEXT: COPY address_results, line 1, column result: "<?xml version="1.0" encoding="UTF-8"?>"
Run Code Online (Sandbox Code Playgroud)
我理解它失败的原因,但无法弄清楚如何\copy将整个文件一次导入单行.
现实描述:我们有一个项目列表.在每个项目中都有很多账户.您可以对每个帐户执行大量操作.我确实有以下维度和事实表定义(简化):
Dimensions and attributes:
Project
project_key
project_name
industry
number_of_accounts
Distance
distance_key
distance_in_months
distance_in_quarters
Account
account_key
project_key
account_id
Fact Table and attributes:
Action_Fact_Table
project_key
distance_key
account_key
action_id
Run Code Online (Sandbox Code Playgroud)
现在,我想使用径流三角形方法来分析数据(它可能不是真正的径流三角形,但方法是相同的).最简单的三角形看起来像:
Distance in Months
Project name| 1 2 3 4 5 6 7 8 9 10
-------------------------------------------------------------------------
Project1 | 5 10 15 20 25 30 35 40 45 50
Project2 | 7 14 21 28 35 42 49 56 63
Project3 | 2 5 8 11 14 20 25 30
Project4 | 0 2 …Run Code Online (Sandbox Code Playgroud) PostgreSQL 9.1
经营情况
每个月都有一批特定流程的新帐户.每个批次都可以按月份,帐户数量和帐户总余额来描述.该过程的目标是从客户那里恢复一些平衡.然后每月单独跟踪每批次(自批次转移到流程以来每月回收的金额).
目标
我的目标是预测将来会收回多少金额.
数据定义
create table vintage_data (
granularity date, /* Month when account entered process*/
distance_in_months integer, /* Distance in months from date when accounts entered process*/
entry_accounts integer, /* Number of accounts that entered process in a given month*/
entry_amount numeric, /* Total amount for account that entered process in a given month*/
recovery_amount numeric /* Amount recovered in Nth month on accounts that entered process in a given month */
);
Run Code Online (Sandbox Code Playgroud)
样本数据
insert into …Run Code Online (Sandbox Code Playgroud) 如何在PostgreSQL中轻松将数字UP上升到10的倍数?
例:
In Out
100 --> 100
111 --> 120
123 --> 130
Run Code Online (Sandbox Code Playgroud)
样本数据:
create table sample(mynumber numeric);
insert into sample values (100);
insert into sample values (111);
insert into sample values (123);
Run Code Online (Sandbox Code Playgroud)
我可以用:
select
mynumber,
case
when mynumber = round(mynumber,-1) then mynumber
else round(mynumber,-1) + 10 end as result
from
sample;
Run Code Online (Sandbox Code Playgroud)
这很好用,但看起来很难看.有更简单的方法吗?
你可以在这里找到SQLFiddle
imagemagick或gimp或其他与linux兼容的工具有什么能够自动检测图像上的单个对象并返回对象的某个位置或将每个对象存储为单独的图像吗?
我有像这样的图像:

对于对象位于网格上的其他图像,我已成功crop在imagemagick中使用运算符,例如3x3网格:
convert -crop 3x3@ in-image.jpg out-image-%d.jpg
Run Code Online (Sandbox Code Playgroud)
crop当没有矩形网格时我无法使用,但我认为白色应足以让对象分离.
我有一个小的bash脚本来OCR PDF文件(稍微修改了这个脚本).每个文件的基本流程是:
对于pdf文件中的每个页面:
脚本:
FILES=/home/tgr/OCR/input/*.pdf
for f in $FILES
do
FILENAME=$(basename "$f")
ENDPAGE=$(pdfinfo $f | grep "^Pages: *[0-9]\+$" | sed 's/.* //')
OUTPUT="/home/tgr/OCR/output/${FILENAME%.*}.txt"
RESOLUTION=1400
touch $OUTPUT
for i in `seq 1 $ENDPAGE`; do
convert -monochrome -density $RESOLUTION $f\[$(($i - 1 ))\] page.tif
echo processing file $f, page $i
tesseract page.tif tempoutput -l ces
cat tempoutput.txt >> $OUTPUT
done
rm tempoutput.txt
rm page.tif
done
Run Code Online (Sandbox Code Playgroud)
由于高分辨率和tesseract只能使用一个核心的事实,这个过程非常慢(转换一个PDF文件大约需要3分钟).
因为我有数以千计的PDF文件,我认为我可以使用parallel所有4个核心,但我没有得到如何使用它的概念.在示例中,我看到:
Nested for-loops like this:
(for x …Run Code Online (Sandbox Code Playgroud) 最近,我发现我一遍又一遍地使用以下模式.过程是:
table在R中,它看起来像这样:
# Sample data
df <- data.frame(x = round(runif(100), 1),
y = factor(ifelse(runif(100) > .5, 1, 0),
labels = c('failure', 'success'))
)
# Get frequencies
dfSummary <- as.data.frame.matrix(table(df$x, df$y))
# Add column of original values from rownames
dfSummary$x <- as.numeric(rownames(dfSummary))
# Remove rownames
rownames(dfSummary) <- NULL
# Reorder columns
dfSummary <- dfSummary[, c(3, 1, 2)]
Run Code Online (Sandbox Code Playgroud)
R中有更优雅的东西,最好是使用基本功能吗?我知道我可以使用sql在单个命令中执行此操作 - 我认为必须有可能在R中实现类似的行为.
sqldf解决方案:
library(sqldf)
dfSummary <- sqldf("select
x,
sum(y = 'failure') as failure,
sum(y = 'success') as …Run Code Online (Sandbox Code Playgroud) 我需要根据列类型对数据框进行子集化 - 例如,从具有100列的数据框中我需要仅保留具有类型factor或列的列integer.我已经编写了一个简短的函数来执行此操作,但CRAN上是否有任何更简单的解决方案或一些内置函数或包?
我目前的解决方案是获取所请求类型的变量名称:
varlist <- function(df=NULL, vartypes=NULL) {
type_function <- c("is.factor","is.integer","is.numeric","is.character","is.double","is.logical")
names(type_function) <- c("factor","integer","numeric","character","double","logical")
names(df)[as.logical(sapply(lapply(names(df), function(y) sapply(type_function[names(type_function) %in% vartypes], function(x) do.call(x,list(df[[y]])))),sum))]
}
Run Code Online (Sandbox Code Playgroud)
该功能的varlist工作原理如下:
还有一些数据要测试它:
df <- read.table(file="http://archive.ics.uci.edu/ml/machine-learning-databases/statlog/german/german.data", sep=" ", header=FALSE, stringsAsFactors=TRUE)
names(df) <- c('ca_status','duration','credit_history','purpose','credit_amount','savings', 'present_employment_since','installment_rate_income','status_sex','other_debtors','present_residence_since','property','age','other_installment','housing','existing_credits', 'job','liable_maintenance_people','telephone','foreign_worker','gb')
df$gb <- ifelse(df$gb == 2, FALSE, TRUE)
df$property <- as.character(df$property)
varlist(df, c("integer","logical"))
Run Code Online (Sandbox Code Playgroud)
我问,因为我的代码看起来真的很神秘,很难理解(即使对我来说,我已经在10分钟前完成了这个功能).
有没有办法如何在PostgreSQL中的每个第n个字符之后拆分字符串?我以为regexp_split_to_array可以用来做到这一点:
select unnest(regexp_split_to_array('abcdefgh', E'...regexp here...'));
Run Code Online (Sandbox Code Playgroud)
输入示例: abcdefgh
必需的输出(每隔第二个字符后分割):
ab
cd
ef
gh
Run Code Online (Sandbox Code Playgroud)
必需的输出(每隔3个字符后分割):
abc
def
gh
Run Code Online (Sandbox Code Playgroud)
什么正则表达式会这样做?还有其他解决方案吗?