dplyr主要用于处理dataframe数据,并植入C++技术以增加运算速度。
点 .
类似于~的一种符号,只收集变量名,而不是名下的值,plyr包多是用“.”来设定变量名表达式。
输出:list of symbol and language primitives
%>%、 %.%
mtcars %>%
head() %>%
print() %>%
add_rownames()
add_rownames
为dataframe增加行名。
all.equal.tbl_df
比较两个dataframe是否相同。
arrange
arrange(mtcars, cyl, disp)
根据cyl,disp的大小排列行(升序)
arrange(mtcars, desc(disp))
##此为降序
as_data_frame
强制转换list为dataframe。
between
x <- rnorm(1e2)
x[between(x, -1, 1)]
between(x, -1, 1)返回TRUE或者FALSE。
mutate
增加新变量。
glimpse
查看数据。
each
联合函数,但不能输入额外的参数。
# Call min() and max() on the vector 1:10
each(min, max)(1:10)
# This syntax looks a little different. It is shorthand for the
# the following:
f<- each(min, max)
f(1:10)
# Three equivalent ways to call min() and max() on the vector 1:10
each("min", "max")(1:10)
each(c("min", "max"))(1:10)
each(c(min, max))(1:10)
# Call length(), min() and max() on a random normal vector
each(length, mean, var)(rnorm(100))

本文深入探讨了dplyr包在数据处理领域的应用,利用C++技术提升DataFrame操作效率。通过使用.d.符号简化变量名表达式,介绍了listofsymbolandlanguageprimitives的输出,以及%>%、%.%等操作符的使用。展示了如何利用mtcars数据集进行数据排序、增加行名、比较数据帧、创建新变量等功能。详细说明了add_rownames、all.equal.tbl_df、arrange、as_data_frame、between、mutate、glimpse、each等函数的具体用法,以及它们在实际数据处理中的重要性。
566

被折叠的 条评论
为什么被折叠?



