我有一个25 col和〜1M行的数据帧组合,分成12个文件,现在我需要导入它们然后使用一些reshape包进行一些数据管理.每个文件都太大了,我不得不寻找一些用于导入和数据处理的"非RAM"解决方案,目前我不需要做任何回归,我将只有一些关于数据帧的描述性统计数据.
我搜索了一下,找到了两个包:ff并且filehash,我先阅读filehash手册,发现它看起来很简单,只是在将数据帧导入文件时添加了一些代码,其余的似乎与通常的R操作类似.
我还没有尝试过ff,因为它有很多不同的课程,我想知道ff在我的实际工作开始之前是否值得投入时间来理解自己.但是filehash包装在某些时候似乎是静态的,并且关于这个包装的讨论很少,我想知道它filehash是否变得不那么流行,甚至变得过时了.
谁能帮我选择使用哪个包?或者任何人都可以告诉我他们之间的区别/利弊是什么?谢谢.
我目前正在使用filehash导入数据帧,并意识到它导入的数据帧filehash应被视为只读,因为该数据帧中的所有进一步修改都不会存储回文件,除非你再次保存,这不是很方便在我看来,因为我需要提醒自己要做到拯救.对此有何评论?
我有一个包含customerid和列表的数据框.我想合并那些与同一客户有关的清单.
library(plyr)
subsets <- list(c("a", "d", "e"), c("a", "b", "c", "e"))
customerids <- c(1,1)
transactions <- data.frame(customerid = customerids,subset =I(subsets))
> transactions
customerid subset
1 1 a, d, e
2 1 a, b, c, e
Run Code Online (Sandbox Code Playgroud)
如果我想将子集与ddply合并,我会得到一个扩展的结果
> ddply(transactions, .(customerid), summarise, subset=Reduce(union,subset))
customerid subset
1 1 a
2 1 d
3 1 e
4 1 b
5 1 c
Run Code Online (Sandbox Code Playgroud)
虽然我希望所有的结果都在一排.
我创建了一个表,如下所示:
CREATE TABLE case_status(data_entry_timestamp DATETIME DEFAULT (datetime('now','localtime')) NOT NULL,
case_number TEXT PRIMARY KEY NOT NULL,
case_name TEXT DEFAULT MISSING,
death_reportdate DATE CONSTRAINT death_reportdate_chk CHECK (death_reportdate==strftime('%Y-%m-%d',death_reportdate)),
);
Run Code Online (Sandbox Code Playgroud)
该列death_reportdate需要具有预定义格式的日期(例如 2000-12-31)。我创建了表,插入了一些数据行,然后尝试修改 中的数据death_reportdate,当我向其中输入一些随机字符串时,检查规则似乎被绕过。
我做错了什么?
我在 Rmarkdown 中使用 kable 创建了一个乳胶表,如下所示:
---
output: pdf_document
header-includes:
- \usepackage{xcolor}
---
```{r, message=FALSE, warning=FALSE, echo=FALSE}
library(kableExtra)
library(tidyr)
library(dplyr)
data(iris)
iris %>%
as_tibble %>%
gather(.,key = variable,value = value,-Species) %>%
group_by(Species,variable) %>%
summarise(value=mean(value)) %>%
ungroup %>%
spread(.,key = variable,value = value) %>%
mutate(`Percentage Change`=`Petal.Length`/`Petal.Width`*100) %>%
kable(.,format='latex',
align='c',linesep='',
booktabs=TRUE,escape=FALSE) %>%
add_header_above(.,c(' '=1,'Parts'=4,' '=1),
escape = FALSE) %>%
kable_styling(latex_options = c('striped','HOLD_position','scale_down'))
```
Run Code Online (Sandbox Code Playgroud)
我希望将列标题“物种”和“百分比变化”分别与它们上面的空白区域合并,这样就Species可以放在两个标题行的中间,同时Percentage Change (Petal Length/ Petal Width)可以占据两行,而不是有一个空的上面的行,并防止其他列下面有空行。
不知道是否可以kable更好地修改它,也欢迎乳胶“黑客”建议。
谢谢!
我正在开发一个python应用程序,使用python和sqlite和GUI重新创建一个Access 2007报告生成应用程序.由于应用程序是可移植的,我正在寻找python的GUI解决方案,用户在使用应用程序之前不需要安装额外的东西.
有没有适合我需要的GUI解决方案?谢谢!
我知道如何使用R创建表table,如下所示:
x <- rep(1:3,4)
y <- rep(1:4,3)
z<- cbind(x,y)
table(z[,1],z[,2])
1 2 3 4
1 1 1 1 1
2 1 1 1 1
3 1 1 1 1
Run Code Online (Sandbox Code Playgroud)
如何将表格的边距总和添加到使其看起来像:
1 2 3 4
1 1 1 1 1 4
2 1 1 1 1 4
3 1 1 1 1 4
3 3 3 3
Run Code Online (Sandbox Code Playgroud) 我有一个列表对象如下:
structure(list(bga_u = structure(list(buy_target_price = numeric(0),
sell_target_price = numeric(0), units_holding = 0, tx_record = structure(list(
`2010-12-01` = structure(list(buy_date = structure(14944, class = "Date"),
offer_price = 40.58, buy_unit = 3.15931809278285,
status = "hold"), .Names = c("buy_date", "offer_price",
"buy_unit", "status")), `2011-01-03` = structure(list(
buy_date = structure(14977, class = "Date"), offer_price = 42.2,
buy_unit = 3.03803621339166, status = "hold"), .Names = c("buy_date",
"offer_price", "buy_unit", "status")), `2011-02-01` = structure(list(
buy_date = structure(15006, class = "Date"), offer_price = 42.59,
buy_unit = 3.01021667539629, status = "hold"), …Run Code Online (Sandbox Code Playgroud) 我创建了一个处理我的一些数据的函数,如下所示:
a <- "old"
test <- function (x) {
assign(x, "new", envir = .GlobalEnv)
}
test(a)
Run Code Online (Sandbox Code Playgroud)
但我看不出从"旧"到"新"的变化,我猜这是一些"全局变量",有什么建议吗?
谢谢!
我在下面创建了一个脚本,用于将unicode转换为中文字符,最后一个字符串temp.df[,"name_unicode"]是"§®£"(没有引号),所以不懂中文的人也可以提供帮助.
library(RODBC)
library(Unicode)
temp.df <- data.frame(name_unicode=c("陳大文",
"陳小敏",
"陳一山",
"§®£"),
stringsAsFactors=FALSE)
temp.df[,"name_unicode_mod"] <- sapply(temp.df[,"name_unicode"],
function(x) {
temp <- unlist(strsplit(x,";"))
temp <- sprintf("%x",as.integer(gsub("[^0-9]","",temp)))
temp <- intToUtf8(as.u_char_range(temp))
return(temp)
})
write.csv(temp.df,file("test.csv",encoding="UTF-8"),row.names=FALSE)
Run Code Online (Sandbox Code Playgroud)
temp.df[,"name_unicode_mod"]R控制台的输出正常.但我需要将它们输出csv或xls格式化.我试过write.csv,write.table,odbcConnectExcel在RODBC但都让我有点像<U+00A7><U+00AE><U+00A3>.
有人可以帮忙吗?谢谢.
PS我使用的是R 3.0.0和Win7
我正在对存储在 sqlserver 中的一些大表进行一些数据处理,这些表创建索引有时会减少运行某些 R 脚本所需的时间。我尝试使用 的mutate功能dplyr创建一个idx具有连续编号的新列 ( ),然后将该idx列用作索引。但是 mutate 功能似乎不起作用并且不断给我这个错误:
> tbl(channel,'tbl_iris') %>% mutate(idx=1:n())
Error in from:to : NA/NaN argument
In addition: Warning message:
In 1:n() : NAs introduced by coercion\
Run Code Online (Sandbox Code Playgroud)
现在我正在做一些对我来说似乎很愚蠢的事情,以“绕过”上述错误消息:
iris <- tbl(channel,'tbl_iris') %>%
collect %>%
mutate(idx=1:n())
try(db_drop_table(channel,'##iris'))
copy_to(channel,iris,'##iris',temporary=FALSE)
db_create_index(channel,'##iris',columns='idx')
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做到这一点?谢谢!
我mutate(idx = row_number())按照@Phil 的建议进行了尝试,但它不起作用并显示以下错误消息:
> tbl(channel,'##iris') %>%
+ mutate(idx=row_number())
Error: <SQL> 'SELECT TOP 10 "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species", row_number() OVER () AS "idx"
FROM …Run Code Online (Sandbox Code Playgroud)