小编the*_*ail的帖子

用最近的gsubfn打破字符串插值?

最后一个例子用来工作,现在却没有.函数内部没有字符串插值?也许它与变量范围有关?有什么建议?

library(gsubfn)
#R.Version() # I'm using 2.15.0, just upgraded from 2.13.something.

### dumb example of a function
g <- function() {for (a in 1:2) { print(paste('is a', a)) }}
g()

### same thing, outside a function, using string interpolation
for (a in 1:2) { fn$print('is a $a') }
rm(a)

### and now string interpolation inside a function
h <- function() {for (a in 1:2) { fn$print('is a $a') }}
h()
Run Code Online (Sandbox Code Playgroud)

最后一个例子告诉我

Error in eval(expr, envir, enclos) : object 'a' not …
Run Code Online (Sandbox Code Playgroud)

debugging r string-interpolation gsub

5
推荐指数
0
解决办法
449
查看次数

在R/GGPLOT2中绘制百分点指示

我有一个两列数据帧的基本图(x ="Periods"和y ="Range").

在此输入图像描述

library (ggplot2)
qplot (Periods, Range, data=twocoltest, color=Periods, size = 3,) + geom_jitter(position=position_jitter(width=0.2))
Run Code Online (Sandbox Code Playgroud)

我试图在下面的每个时期添加一条水平线,该水平线占该时期所有观测值的90%.(它不必是水平线,每个时期的任何视觉指示就足够了).

任何帮助将不胜感激.

r line horizontal-line ggplot2 quantile

5
推荐指数
1
解决办法
2228
查看次数

R中的函数lapply(x,'[[,VarNames [[type]])中的[["意味着什么?

谁能告诉我 R [[ 中的功能有什么意义lapply(x, '[[', VarNames[[type]])?非常感谢!

r

5
推荐指数
1
解决办法
2931
查看次数

R:在y轴上具有分钟和秒的箱线图

当我boxplot在R中以秒为单位测量一些数据时,如何将y轴的比例从秒改为分钟和秒?

例如,当我做这样的事情时:

data <- c(298, 507, 1008, 346)
boxplot(data)
Run Code Online (Sandbox Code Playgroud)

我得到一个boxploty轴从300到1000.我想在那里有"5:00"到"16:40",只需将秒转换为分钟和秒.

datetime r boxplot

5
推荐指数
1
解决办法
1139
查看次数

以递归方式从多个列表中cbind项目

鉴于三个(或n列表):

one   <- list(a=1:2,b="one")
two   <- list(a=2:3,b="two")
three <- list(a=3:4,b="three")
Run Code Online (Sandbox Code Playgroud)

为了得到这个结果,cbindn列表中列出每个列表项的更有效方法是什么?

mapply(cbind,mapply(cbind,one,two,SIMPLIFY=FALSE),three,SIMPLIFY=FALSE)

$a
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    3    4

$b
     [,1]  [,2]  [,3]   
[1,] "one" "two" "three"
Run Code Online (Sandbox Code Playgroud)

当这工作好n23,但很快将成为可笑复杂.这有更有效的变化吗?我在SO上看过类似的问题,但一直在努力调整它们.

join r list cbind

5
推荐指数
2
解决办法
5682
查看次数

如何使用ddply计算数据框中每个单元格的百分比?

我的猜测是使用ddply很容易,但我仍然是R的新手,无法理解它.

我有一个看起来像这样的data.frame

txt <- "label var1 var2 var3 var4 var5 var6 var7
lab1 401 80 57 125 118 182 83
lab2 72 192 80 224 182 187 178
lab3 7 152 134 104 105 80 130
lab4 3 58 210 30 78 33 87
lab5 1 2 3 1 1 2 6"

mydata <- read.table(textConnection(txt), sep = " ", header = TRUE)
Run Code Online (Sandbox Code Playgroud)

这样做我可以一次将一个变量转换为百分比

mydata$var1 <- round(prop.table(mydata$var1),3)*100
Run Code Online (Sandbox Code Playgroud)

但是如何在一个笔划中的data.frame中使用所有变量(var1:var7)呢?

注意:它进入一个函数,其中变量的长度和数量不时变化,因此代码应该对此敏感.

先感谢您

r plyr

5
推荐指数
2
解决办法
1602
查看次数

重新排列R中的数据框

所以我的R输出看起来像这样

Time    50  100  150  200  250  300  350
Carla  1.2  1.8  2.2  2.3  3.0  2.5  1.8
Mace   1.5  1.1  1.9  2.0  3.6  3.0  2.5
Lea    1.7  1.6  2.3  2.7  2.6  2.2  2.6
Karen  1.3  1.7  1.9  2.2  3.2  1.5  1.9
Run Code Online (Sandbox Code Playgroud)

我希望它看起来像这样

Time  Score   Name
50    1.2     Carla
50    1.5     Mace
50    1.7     Lea
50    1.3     Karen
100   1.8     Carla
100   1.5     Mace
100   1.7     Lea
100   1.3     Karen
Run Code Online (Sandbox Code Playgroud)

我该如何将其转换为此?谢谢

r transform

5
推荐指数
1
解决办法
6789
查看次数

cannot open connection in an r script that worked previously

I am having a "cannot open the connection" error in an R script. Below are the details:

> write.csv(table1.fiveReitWts,file="C:\\Users\\John Broussard\\Dropbox\\evtHandbookProject\\figuresTables\\figure3Data.csv")
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file 'C:\Users\John Broussard\Dropbox\evtHandbookProject\figuresTables\figure3Data.csv': No such file or directory
> 
Run Code Online (Sandbox Code Playgroud)

This is a new file being created, but the directory exists. I can see the directory, which contains other files. I have used this code previously with success, …

r

5
推荐指数
1
解决办法
7410
查看次数

如何为我用 R 编写的函数创建帮助?

我想为我自己的功能创建帮助页面。所以如果我定义一个函数:例如:

myfunct <- function(x,y,z){...}
Run Code Online (Sandbox Code Playgroud)

如果我输入,?myfunct我会得到我给出的参数规格。

有没有办法做到这一点?

r function

5
推荐指数
1
解决办法
2360
查看次数

在R中删除过于常见的单词(出现在80%以上的文档中)

我正在使用'tm'包来创建语料库.我已经完成了大部分预处理步骤.剩下的就是删除过于常见的单词(超过80%的文档中出现的术语).任何人都可以帮我吗?

dsc <- Corpus(dd)
dsc <- tm_map(dsc, stripWhitespace)
dsc <- tm_map(dsc, removePunctuation)
dsc <- tm_map(dsc, removeNumbers)
dsc <- tm_map(dsc, removeWords, otherWords1)
dsc <- tm_map(dsc, removeWords, otherWords2)
dsc <- tm_map(dsc, removeWords, otherWords3)
dsc <- tm_map(dsc, removeWords, javaKeywords)
dsc <- tm_map(dsc, removeWords, stopwords("english"))
dsc = tm_map(dsc, stemDocument)
dtm<- DocumentTermMatrix(dsc, control = list(weighting = weightTf, 
                         stopwords = FALSE))

dtm = removeSparseTerms(dtm, 0.99) 
# ^-  Removes overly rare words (occur in less than 2% of the documents)
Run Code Online (Sandbox Code Playgroud)

r text-mining tm

5
推荐指数
2
解决办法
9218
查看次数