什么是命令行编织器相当于R CMD Sweave myfile.rnw?
在knitr中使用R Markdown是否与\Sexpr{}Sweave 相当?
我经常需要从R中的data.frame中选择一组变量.我的研究是在社会和行为科学中,并且拥有一个包含数百个变量的data.frame是很常见的(例如,会有一系列调查问题,人口统计项目,绩效衡量指标等的项目级别信息.
作为分析的一部分,我经常想要选择变量的子集.例如,我可能想得到:
现在,我知道有很多方法可以编写代码来选择变量子集. Quick-r概述了从data.frame中提取变量子集的常用方法.
例如,
myvars <- c("v1", "v2", "v3")
newdata <- mydata[myvars]
Run Code Online (Sandbox Code Playgroud)
但是,我对此过程的效率感兴趣,特别是在您可能需要从data.frame中提取20个左右的变量时.变量的命名惯例通常是不直观,尤其是当你继承了别人的数据集,所以你可能在想,是可变的Gender,gender,sex,GENDER,gender1,等20个变数,需要提取乘以这个,记忆变量名的任务变得比它需要的更复杂.
为了使下面的讨论具体,我将bfi在psych包中使用data.frame .
library(psych)
data(bfi)
df <- bfi
head(df, 1)
A1 A2 A3 A4 A5 C1 C2 C3 C4 C5 E1 E2 E3 E4 E5 N1 N2 N3 N4 N5 O1 O2 O3 O4
61617 2 4 3 4 4 2 3 3 4 4 3 …Run Code Online (Sandbox Code Playgroud) 我正在运行Ubuntu 11.10,我希望能够写入剪贴板(或主要选择).以下是错误
> x <- 1:10
> dput(x, 'clipboard')
Error in file(file, "wt") : 'mode' for the clipboard must be 'r' on Unix
Run Code Online (Sandbox Code Playgroud)
如何写入剪贴板/主要选择?
请注意,我已经看过这个旧的R-Help帖子,但我仍然不清楚我应该做什么.
Linux没有剪贴板,但X11会话具有主要和次要选择.?文件说
剪贴板:
Run Code Online (Sandbox Code Playgroud)'file' can also be used with 'description = "clipboard"' in mode '"r"' only. It reads the X11 primary selection, which can also be specified as '"X11_primary"' and the secondary selection as '"X11_secondary"'. When the clipboard is opened for reading, the contents are immediately copied to internal storage in the connection. Unix …
我为一个使用S3类的函数创建了一个roxygen文件.我roxygenize然后建立并检查并得到一个警告:
* checking S3 generic/method consistency ... WARNING
common:
function(word.list, ...)
common.list:
function(word.list, overlap, equal.or)
See section 'Generic functions and methods' of the 'Writing R
Extensions' manual.
Run Code Online (Sandbox Code Playgroud)
所以我花时间学习:
http://cran.r-project.org/doc/manuals/R-exts.html#Generic-functions-and-methods & https://github.com/hadley/devtools/wiki/S3
但我无法弄清楚我在下面的文件中做错了什么.该功能按预期工作.
1)为什么会发出警告?2)我怎么能让它消失?
#' Find Common Words Between Groups
#'
#' Find common words between grouping variables (e.g. people).
#'
#' @param word.list A list of names chacter vectors.
#' @param overlap Minimum/exact amount of overlap.
#' @param equal.or A character vector of c(\code{"equal"}, \code{"greater"},
#' \code{"more"}, \code{"less"}).
#' @param …Run Code Online (Sandbox Code Playgroud) 我有一个数据帧,我希望舍入所有数字(准备导出).这必须是直截了当的,但我遇到了问题,因为数据帧的某些位不是数字.例如,我想在下面的例子中将数字四舍五入到最接近的整数:
ID = c("a","b","c","d","e")
Value1 = c("3.4","6.4","8.7","1.1","0.1")
Value2 = c("8.2","1.7","6.4","1.9","10.3")
df<-data.frame(ID,Value1,Value2)
Run Code Online (Sandbox Code Playgroud)
谁能帮我吗?我可以围绕单个列(例如round(df$Value1, 2)),但我想围绕一个包含一些非数字列的整个表.
我正在尝试使用R Markdown编写R Package vignet.我正在使用R Studio的包创作工具.
我的R大于3.0版.
我在vignettes文件夹中有一个.Rmd文件,顶部包含以下文本:
<!--
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{An Introduction to the bootcorrelations package}
-->
Run Code Online (Sandbox Code Playgroud)
我的DESCRIPTION文件中有以下内容:
VignetteBuilder: knitr
Suggests: knitr
Run Code Online (Sandbox Code Playgroud)
当我在RStudio中清理和构建或重新加载包时,会显示插图源,但不显示HTML(即,没有HTML文件inst/man).

如何让RStudio从R Markdown Vignette自动创建HTML?
我已经阅读了Yihui关于使用Markdown的R Package Vignettes的帖子,它建议使用makefile,但是这个关于knitr vignettes的最新文档表明不再需要makefile.
我也意识到我可以使用如下命令手动创建HTML插图:
library(knitr)
knit(input='vignettes/foo.Rmd', output='inst/doc/foo.md')
library(markdown)
markdownToHTML('inst/doc/foo.md', 'inst/doc/foo.html')
Run Code Online (Sandbox Code Playgroud)
一个可重复的例子:
Vectorize(dir.create)(c("test", "test/R", "test/man", "test/vignettes"))
cat(
'Package: test
Title: Test pkg
Description: Investigate how to auto-compile markdown vignettes
Version: 0.0-1
Date: 2015-03-15
Author: Jeromy Anglim
Maintainer: Jeromy Anglim <a@b.com>
Suggests: knitr
License: …Run Code Online (Sandbox Code Playgroud) 说我有以下文字
word1 word2 word3 word4
Run Code Online (Sandbox Code Playgroud)
并且光标位于word2和之间word3.
word2,并word3在Vim的一个空间?:s/ */ /g但是,我认为可能有更快的东西,diw但空间.
这也将是一件好事,如果该战略还努力当光标是对w的word3或2或word2.
我有一个我想在R中打开的excel文件.在将excel文件保存为csv文件或文本文件后,我尝试了这两个命令.
read.table()或read.csv()
我认为问题的一部分是文件所在的位置.我把它保存在桌面上.我在这里错过了什么?
这是R输出
In file(file, "rt") :
cannot open file 'Rtrial.csv': No such file or directory
> help.search("read.csv")
> read.csv("Rtrial.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'Rtrial.csv': No such file or directory
> read.table("tab")
Run Code Online (Sandbox Code Playgroud) 这可能是一个简单的答案,已被无数次回答.我只是缺乏搜索答案的术语.
我正在创建一个包.当程序包加载时,我希望能够即时访问数据集.
所以我们说DICTIONARY是一个数据集.
我希望能够做DICTIONARY而不是data(DICTIONARY)让它加载.我该怎么做呢?