当使用read_fwfpandas(0.18.1)中的函数和Python(3.4.3)读取固定宽度文件时,可以使用comment参数指定注释字符.我希望所有以注释字符开头的行都会被忽略.但是,如果未在任何列中的文件中指定第一列,则colspecs似乎不会使用注释字符.
import io, sys
import pandas as pd
sys.version
# '3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)]'
pd.__version__
# '0.18.1'
# Two input files, first line is comment, second line is data.
# Second file has a column (with the letter A)
# that I don't want at start of data.
string = "#\n1K\n"
off_string = "#\nA1K\n"
# When using skiprows to skip commented row, both work.
pd.read_fwf(io.StringIO(string), colspecs = …Run Code Online (Sandbox Code Playgroud) 如何区分4种不同的因素(不使用大小)?是否可以使用空心点和实心点来区分ggplot2中的变量?
test=data.frame(x=runif(12,0,1),
y=runif(12,0,1),
siteloc=as.factor(c('a','b','a','b','a','b','a','b','a','b','a','b')),
modeltype=as.factor(c('q','r','s','q','r','s','q','r','s','q','r','s')),
mth=c('Mar','Apr','May','Mar','Apr','May','Mar','Apr','May','Mar','Apr','May'),
yr=c(2010,2011,2010,2011,2010,2011,2010,2011,2010,2011,2010,2011))
Run Code Online (Sandbox Code Playgroud)
其中x是观测值,y是建模结果,我想比较几个因素的不同模型版本.谢谢!
我完全有可能忽略了一些东西,但是当使用RSQLite包时,是否仍然可以在R脚本中使用特殊字符串":memory:"来加速数据检索?
我在更改包生成的风玫瑰图中的字体大小时遇到困难openair。情节windRose没问题。但该包的文档似乎没有指定如何更改标题、标签和刻度的字体大小。
par(cex.lab=, cex.axis=, cex.main=, cex.sub=)
Run Code Online (Sandbox Code Playgroud)
似乎也不起作用。
有谁知道放大字体的方法吗?我们将非常感谢您的帮助!
这是我试图绘制的可重现示例:
library(openair)
df<-read.csv('http://www.openair-project.org/CSV/OpenAir_example_data_long.csv')
windRose(df)
Run Code Online (Sandbox Code Playgroud)

我有一个像这样的数据框(RNA.patients):
PAK1|5808
PAK2|10289
PALM2|114299
PALM2-AKAP2|445815
Run Code Online (Sandbox Code Playgroud)
我想抓住所有东西直到"|",所以我找到了这个正则表达式:
regmatches(RNA.patients[i,1], regexpr("^[^[:punct:]]*", RNA.patients[i,1]))
Run Code Online (Sandbox Code Playgroud)
但对于像"PALM2-AKAP2"这样的情况,正则表达式停在" - "处.有谁可以帮助我吗?
我从CSV文件中导入了一个包含奇怪格式数字数据的大数据帧.这是我正在使用的数据框的可重现示例:
df <- data.frame("r1" = c(1,2,3,4,5), "r2" = c(1,2.01,-3,"-","2,000"))
Run Code Online (Sandbox Code Playgroud)
'r2'包含带负号的值,例如" - ",带零的值表示为破折号' - '.要对这个凌乱的r2列进行一些数值分析,我需要:
foo$row2<- as.numeric(sub("-",0,foo$row2))R将用逗号格式化的值强制转换为NA,从而破坏列中的数据.以下是运行后的输出示例foo$row2<- as.numeric(sub("-",0,foo$row2)):
Warning message:
NAs introduced by coercion
r1 r2
1 1 1.00
2 2 2.01
3 3 3.00
4 4 0.00
5 5 NA
Run Code Online (Sandbox Code Playgroud)
如你所见,"2,000"被强迫给NA.-3错误地转换为3(删除了短划线).但是,嘿,至少我们摆脱了第3排的" - ",对!
这最终是我想要制作的:
r1 r2
1 1 1.00
2 2 2.01
3 3 -3.00
4 4 0.00
5 5 2000
Run Code Online (Sandbox Code Playgroud)
请注意,第5行中的逗号将被删除.列r2应格式化,以便我可以运行类似的命令sum(df$r2).
我有一个data.frame,我想用一列相对于其他列(框架中也有一些非数字列)来计算相关系数。
ddply(Banks,.(brand_id,standard.quarter),function(x) { cor(BLY11,x) })
# Error in cor(BLY11, x) : 'y' must be numeric
Run Code Online (Sandbox Code Playgroud)
我针对is.numeric(x)进行了测试
ddply(Banks,.(brand_id,standard.quarter),function(x) { if is.numeric(x) cor(BLY11,x) else 0 })
Run Code Online (Sandbox Code Playgroud)
但是每次比较都失败,返回0,仅返回一列,就好像它仅被调用过一次一样。什么传递给该函数?刚来到R,我认为我缺少一些基本知识。
谢谢
很多帖子(比如这个)都声称这个ff软件包优于,bigmemory因为它可以处理具有原子和非原子组件的对象,但是如何?例如:
UNIT <- c(100,100, 200, 200, 200, 200, 200, 300, 300, 300,300)
STATUS <- c('ACTIVE','INACTIVE','ACTIVE','ACTIVE','INACTIVE','ACTIVE','INACTIVE','ACTIVE',
'ACTIVE','ACTIVE','INACTIVE')
TERMINATED <- as.Date(c('1999-07-06','2008-12-05','2000-08-18','2000-08-18','2000-08-18',
'2008-08-18','2008-08-18','2006-09-19','2006-09-19','2006-09-19',
'1999-03-15'))
START <- as.Date(c('2007-04-23','2008-12-06','2004-06-01','2007-02-01','2008-04-19',
'2010-11-29','2010-12-30','2007-10-29','2008-02-05','2008-06-30',
'2009-02-07'))
STOP <- as.Date(c('2008-12-05','2012-12-31','2007-01-31','2008-04-18','2010-11-28',
'2010-12-29','2012-12-31','2008-02-04','2008-06-29','2009-02-06',
'2012-12-31'))
TEST <- data.frame(UNIT,STATUS,TERMINATED,START,STOP)
TEST
#install.packages('ff')
library('ff')
TEST2 <- ffdf(TEST)
Error in ffdf(TEST) : ffdf components must be atomic ff objects
Run Code Online (Sandbox Code Playgroud)
我能做些什么来完成这项工作?
r ×7
bigdata ×1
correlation ×1
dataframe ×1
font-size ×1
ggplot2 ×1
openair ×1
pandas ×1
plyr ×1
python ×1
python-3.x ×1
regex ×1
sqlite ×1
statistics ×1