我有一个data.frame,我需要计算每组的平均值(即每个Month,下面).
Name Month Rate1 Rate2
Aira 1 12 23
Aira 2 18 73
Aira 3 19 45
Ben 1 53 19
Ben 2 22 87
Ben 3 19 45
Cat 1 22 87
Cat 2 67 43
Cat 3 45 32
Run Code Online (Sandbox Code Playgroud)
我的期望的输出是像下面,其中对于所述的值Rate1和Rate2是组装置.请忽略这个值,我已经为这个例子做了补充.
Name Rate1 Rate2
Aira 23.21 12.2
Ben 45.23 43.9
Cat 33.22 32.2
Run Code Online (Sandbox Code Playgroud) 我使用的是geom_smooth()从ggplot2.
在Hadley Wickham的书("ggplot2 - 用于数据分析的优雅图形")中,有一个例子(第51页),其中method="lm"使用了它.在联机手册不存在的通话method参数.我看到其他人使用的Google搜索结果(以及此处的问题)method='loess'.
是否有一个详尽的清单解释了选项?
从我所看到的,'lm'绘制一条直线,'loess'绘制一条非常平滑的曲线.我假设还有其他人在参考点之间绘制了更多的锯齿线?
se示例中的参数也不在帮助或在线文档中.
FWIW这是我的代码.
p <- ggplot(output8, aes(age, myoutcome, group=id, colour=year_diag_cat2)) +
geom_line() + scale_y_continuous(limits = c(lwr,upr))
p + geom_smooth(aes(group=year_diag_cat2), method="loess", size=2, se=F)
Run Code Online (Sandbox Code Playgroud) 对于某人来说,这可能是一个非常简单的问题 - 我可以用来list.files()获取给定目录中的文件列表,但是如果我想获得目录列表,我该怎么做?它在某种程度上就在我面前作为一种选择list.files()吗?
此外,我正在使用Windows,所以如果答案是支持某些Linux/unix命令,那对我来说无效.
.NET例如有一个Directory.GetFiles()方法和一个单独的Directory.GetDirectories()
方法,所以我认为R会有一个类似的对.提前致谢.
考虑一个字符向量,pool其元素是(零填充)二进制数,最多为max_len数字.
max_len <- 4
pool <- unlist(lapply(seq_len(max_len), function(x)
do.call(paste0, expand.grid(rep(list(c('0', '1')), x)))))
pool
## [1] "0" "1" "00" "10" "01" "11" "000" "100" "010" "110"
## [11] "001" "101" "011" "111" "0000" "1000" "0100" "1100" "0010" "1010"
## [21] "0110" "1110" "0001" "1001" "0101" "1101" "0011" "1011" "0111" "1111"
Run Code Online (Sandbox Code Playgroud)
我想品尝n这些元素,与约束,没有一个采样的元素是前缀的任何其他采样元素(即如果我们品尝1101,我们禁止1,11和110,而如果我们品尝1,我们禁止这些元素开始用1,例如10,11,100等等).
以下是我尝试使用的while,但当n …
我有一个矩阵m和一个向量v.我想将第一列矩阵乘以m向量的第一个元素v,并将第二列矩阵乘以向量的第二m个元素v,依此类推.我可以使用以下代码完成它,但我正在寻找一种不需要两个转置调用的方法.我怎样才能在R中更快地做到这一点?
m <- matrix(rnorm(120000), ncol=6)
v <- c(1.5, 3.5, 4.5, 5.5, 6.5, 7.5)
system.time(t(t(m) * v))
# user system elapsed
# 0.02 0.00 0.02
Run Code Online (Sandbox Code Playgroud) 在R中,包probability=TRUE的svm功能有e1071什么功能?
model <- svm (Type ~ ., data, probability=TRUE, cost = 100, gamma = 1)
Run Code Online (Sandbox Code Playgroud) 在R,哪能inner_join多tbls或data.frame小号有效?
例如:
devtools::install_github("rstudio/EDAWR")
library(EDAWR)
library(dplyr)
data(songs)
data(artists)
test <- songs
colnames(test) <- c("song2", "name")
inner_join(songs, artists,by="name") %>% inner_join(test,by="name")
Run Code Online (Sandbox Code Playgroud)
有数百个test样data.frames,我想加入.
How can I get the size of the plot window in R? I've been using xwininfo, but there must be a function or variable in R to extract the current plot height and width.
UPDATE
This works as a savePlot() replacement if you don't have Cairo support and you want to export plots to Windows or other 100 dpi devices:
dev.copy(png, "myplot.png", width=dev.size("px")[1], height=dev.size("px")[2],
res=100, bg="transparent")
dev.off()
Run Code Online (Sandbox Code Playgroud) 我有一个意图服务,下载几千兆字节的视频.我有一个"停止"按钮,如果意外点击"开始"或其他什么,停止下载.我知道这已被问过几次,但对我没有工作答案.
我试着打电话stopService(),不行.那只是打电话IntentService.OnDestroy().我试着打电话stopSelf()进去onDestroy,也没办法.
我尝试过像标志一样的东西,但如果onHandleIntent已经在运行,它就不会被调用,它等待当前的工作完成并执行.即使这会起作用,我也不得不像巨型if语句一样,这很糟糕
我唯一的选择是将其重写为常规服务吗?
//回答
public class SyncService extends IntentService {
boolean isCanceled;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent.hasExtra("action")) {
// Set the canceling flag
isCanceled= intent.getStringExtra("action").equals("cancel");
}
return super.onStartCommand(intent, flags, startId);
}
@Override
protected void onHandleIntent(Intent intent) {
// Clean up the possible queue
if (intent.hasExtra ("action")) {
boolean cancel = intent.getStringExtra ("action"). Equals ("cancel");
if (cancel) {
return;
}
}
...
Get your inputStream …Run Code Online (Sandbox Code Playgroud)