我在下面有2个数字列表(col1和col2).我想添加2列(col3和col4),它们执行以下操作.每次col2改变时,col3编号col2从1开始(例如从b2到b3).对于col2中的每个值,col4在最后一次出现时为TRUE.
数据按col1排序,然后col2开始.注意.col2中的值可以出现在col1的不同值中.(即我可以为col 1(a,b,c)的每个值都有b1)
我可以在大约5000行(约6秒)内正常工作,但可以缩放到大约100万行.
这是我的代码
df$col3 <- 0
df$col4 <- FALSE
stopHere <- nrow(df)
c1 <- 'xxx'
c2 <- 'xxx'
for (i in 1:stopHere) {
if (df[i, "col1"] != c1) {
c2 <- 0
c3 <- 1
c1 <- df[i, "col1"]
}
if (df[i, "col2"] != c2) {
df[i - 1, "col4"] <- TRUE
c3 <- 1
c2 <- df[i, "col2"]
}
df[i, "col3"] <- c3
c3 <- c3 + 1
}
Run Code Online (Sandbox Code Playgroud)
这是我想要的输出.
1 a b1 1 FALSE
2 a …
Run Code Online (Sandbox Code Playgroud) 是否可以在同一图上绘制两组数据,但每组使用不同的调色板?
testdf <- data.frame( x = rnorm(100),
y1 = rnorm(100, mean = 0, sd = 1),
y2 = rnorm(100, mean = 10, sd = 1),
yc = rnorm(100, mean = 0, sd = 3))
ggplot(testdf, aes(x, y1, colour = yc)) + geom_point() +
geom_point(aes(y = y2))
Run Code Online (Sandbox Code Playgroud)
我想看的是一组数据,比如y1
蓝色(颜色设置yc
),另一组红色(再次颜色设置yc
).
然后,图例应显示2个色标,一个为蓝色,另一个为红色.
谢谢你的建议.
我在运行Lion的MacbookPro上安装pyenchant时遇到了麻烦.我用自制软件和点子来安装附魔和诡计
自制软件安装附魔
pip install pyenchant
我还下载了一个英文字典到以下文件夹:
/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/enchant/share/enchant/myspell
-rw-r--r-- 1 mycomputer admin 75 Jun 6 13:34 README.txt
-rw-rw-rw-@ 1 mycomputer staff 1017 May 4 2007 README_en_US.txt
drwx------@ 2 mycomputer staff 68 Jun 6 13:38 en_US
-rw-rw-rw-@ 1 mycomputer staff 3045 May 4 2007 en_US.aff
-rw-rw-rw-@ 1 mycomputer staff 696131 May 4 2007 en_US.dic
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用附魔时,我收到以下错误.
>>> import enchant
>>> d = enchant.Dict('en_US')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/enchant/__init__.py", line 502, in __init__
self._switch_this(broker._request_dict_data(tag),broker)
File "/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/enchant/__init__.py", …
Run Code Online (Sandbox Code Playgroud)