我正在尝试创建一个函数,根据它们的位置选择DF中的列.我将始终需要第一列,然后是DF的子集.我需要为每个子集选择一个对象.
到目前为止,我尝试了以下内容:
position <- "1,28:31"
DF %>%
select_(.dots = position)
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
解析时出错(text = x):: 1:2:意外'x'
似乎问题是列位置的逗号分离.
有解决方法吗?
由于我已经更新到ggplot2 2.0.0,我无法使用gridExtra正确排列图表.问题是分面图表会被压缩,而其他图表会扩展.宽度基本搞砸了.我想安排它们类似于这些单面图的方式:左对齐两个图形边(ggplot)
我把一个可重现的代码
library(grid) # for unit.pmax()
library(gridExtra)
plot.iris <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point() +
facet_grid(. ~ Species) +
stat_smooth(method = "lm")
plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) +
geom_point(size=2.5)
g.iris <- ggplotGrob(plot.iris) # convert to gtable
g.mpg <- ggplotGrob(plot.mpg) # convert to gtable
iris.widths <- g.iris$widths # extract the first three widths,
mpg.widths <- g.mpg$widths # same for mpg plot
max.widths <- unit.pmax(iris.widths, mpg.widths)
g.iris$widths <- max.widths # assign max. widths …Run Code Online (Sandbox Code Playgroud) 我有一个数据集,我想对其进行平均值总结,但也计算其中 1 个变量的最大值。
\n\n让我从一个我想要实现的目标开始:
\n\niris %>%\n group_by(Species) %>%\n filter(Sepal.Length > 5) %>%\n summarise_at("Sepal.Length:Petal.Width",funs(mean))\nRun Code Online (Sandbox Code Playgroud)\n\n这给了我以下结果
\n\n# A tibble: 3 \xc3\x97 5\n Species Sepal.Length Sepal.Width Petal.Length Petal.Width\n <fctr> <dbl> <dbl> <dbl> <dbl>\n1 setosa 5.8 4.4 1.9 0.5\n2 versicolor 7.0 3.4 5.1 1.8\n3 virginica 7.9 3.8 6.9 2.5\nRun Code Online (Sandbox Code Playgroud)\n\n有没有简单的方法来添加,例如max(Petal.Width)总结?
到目前为止,我已经尝试过以下方法:
\n\niris %>%\n group_by(Species) %>%\n filter(Sepal.Length > 5) %>%\n summarise_at("Sepal.Length:Petal.Width",funs(mean)) %>%\n mutate(Max.Petal.Width = max(iris$Petal.Width))\nRun Code Online (Sandbox Code Playgroud)\n\n但通过这种方法,我丢失了上面代码中的group_by和,并给出了错误的结果。filter
我能够实现的唯一解决方案如下:
\n\niris %>%\n group_by(Species) …Run Code Online (Sandbox Code Playgroud)