我正在使用 Rcpp 来加速在 R(3.4,Windows7)中重复调用的函数,我希望更改编译器设置。
当我打电话时:
sourceCpp("scoreseq1.1.cc", verbose=TRUE)
部分输出内容如下:
C:/RBuildTools/3.4/mingw_64/bin/g++ -I"C:/PROGRA~1/R/R-34~1.1/include" -O2 -Wall -mtune=core2 -c Scoreseq1.1.cc -o Scoreseq1 .1.o
我想更改-mtune为haswell、 和 ,-O2以-O3寻求一些性能改进。
有没有办法通过sourceCpp或 来做到这cppFunction一点,我是否需要在 my.cc 文件中使用特殊标头,或者我是否需要修改系统上的某些文件(如果是,是什么文件?!)
谢谢!
我有一个R数据框,其中有一列数据框,我想将每列数据打印到一个文件中:
df0 <- tibble(x = 1:3, y = rnorm(3))
df1 <- tibble(x = 1:3, y = rnorm(3))
df2 <- tibble(x = 1:3, y = rnorm(3))
animalFrames <- tibble(animals = c('sheep', 'cow', 'horse'),
frames = list(df0, df1, df2))
Run Code Online (Sandbox Code Playgroud)
我可以使用for循环来做到这一点:
for (i in 1:dim(animalFrames)[1]){
write.csv(animalFrames[i,2][[1]], file = paste0('test_', animalFrames[i,1], '.csv'))
}
Run Code Online (Sandbox Code Playgroud)
或具有purrr的walk2功能:
walk2(animalFrames$animals, animalFrames$frames, ~write.csv(.y, file
= paste0('test_', .x, '.csv')))
Run Code Online (Sandbox Code Playgroud)
有什么方法可以将此游走功能放在magrittr管道的末端?
我在想类似的东西:
animalFrames %>% do({walk2(.$animals, .$frames, ~write.csv(.y, file = paste0('test_', .x, '.csv')))})
Run Code Online (Sandbox Code Playgroud)
但这给我一个错误:
Run Code Online (Sandbox Code Playgroud)Error: Result must …
使用dplyr以下命令可以轻松创建新列mutate:
df <- data.frame(v1 = 1:3, v2 = c('a','b','c'))
> mutate(df, newcol = NA)
v1 v2 newcol
1 1 a NA
2 2 b NA
3 3 c NA
Run Code Online (Sandbox Code Playgroud)
我们还可以使用向量创建多个新列mutate_at(如下所示):
> cnames <- c('newcol1', 'newcol2', 'newcol3')
> mutate_at(df, cnames, funs(log(v1)))
v1 v2 newcol1 newcol2 newcol3
1 1 a 0.0000000 0.0000000 0.0000000
2 2 b 0.6931472 0.6931472 0.6931472
3 3 c 1.0986123 1.0986123 1.0986123
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法可以使用 来将这些新列初始化为 NA dplyr?
例如,mutate_at(df, cnames, funs(v1 …
我有一个如下所示的 DataFrame:
>>> df = pd.DataFrame({
'category1': list('AABAAB'),
'category2': list('xyxxyx'),
'year': [2000, 2000, 2000, 2002, 2002, 2002],
'value': [0, 1, 0, 4, 3, 4]
})
>>> df
category1 category2 year value
0 A x 2000 0
1 A y 2000 1
2 B x 2000 0
3 A x 2002 4
4 A y 2002 3
5 B x 2002 4
Run Code Online (Sandbox Code Playgroud)
我想扩展数据以包括某个范围内的缺失年份。例如,如果范围是range(2000, 2003),则扩展后的 DataFrame 应如下所示:
category1 category2 year value
0 A x 2000 0.0
1 A y 2000 …Run Code Online (Sandbox Code Playgroud) 这是一个简单的问题,我似乎找不到优雅的解决方案。我正在尝试选择数据框的行,其中两列从单独的列表中形成一对。
例如:
import pandas as pd
df = pd.DataFrame({'a': range(8), 'b': range(8), 'c': list('zyxwvuts')})
pairs = [(4, 4), (5, 6), (6, 6), (7, 9)]
# The data has an arbitrary number of columns, but I just want
# to match 'a' and 'b'
df
a b c
0 0 0 z
1 1 1 y
2 2 2 x
3 3 3 w
4 4 4 v
5 5 5 u
6 6 6 t
7 7 7 s
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我的列表 …
我想plotly基于我的数据中的一列离散值来过滤使用创建的图表.最终目标是能够使用按钮来更新过滤器值,因此我不想事先过滤数据.
library(plotly)
df <- data.frame(group1 = rep(c('low', 'high'), each = 25),
x = rep(1:5, each = 5),
group2 = letters[1:5],
y = c(runif(25, 0, 2), runif(25, 3, 5)))
plot_ly(df, x = ~x, y = ~y, type = 'scatter',
mode = 'line',
color = ~group2,
transforms = list(
list(
type = 'filter',
target = ~group1,
operation = '=',
value = 'high'
)
)
)
Run Code Online (Sandbox Code Playgroud)
我希望这会给出以下图表:
但相反它给出了这个:
它似乎是在错误的变量上过滤.为什么不按照我预期的方式过滤数据?