小编nei*_*fws的帖子

r如何快速清除所有全球环境

是否有一个功能或命令,R这可以清除所有的global environment,就像clearMatlabrm如果我想删除它,我只知道需要我将每个变量名放入其中的函数。那真的不方便。

谢谢

r

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

如何获取每个唯一ID的摘要

我想为多列中的多个值提取一些摘要统计信息.我的数据如下

id                pace       type                   value      abundance 
51                (T)        (JC)                   (L)           0        
51                (T)        (JC)                   (L)           0 
51                (T)        (JC)                   (H)           0
52                (T)        (JC)                   (H)           0
52                (R)        (JC)                   (H)           0
53                (T)        (JC)                   (L)           1
53                (T)        (JC)                   (H)           1
53                (R)        (JC)                   (H)           1
53                (R)        (JC)                   (H)           1
53                (R)        (JC)                   (H)           1
54                (T)        (BC)                 <blank>         0          

54                (T)        (BC)                 <blank>         0 
54                (T)        (BC)                 <blank>         0
Run Code Online (Sandbox Code Playgroud)

我希望这样的事情

id    ptype       (T)    (R)        (L)      (H)     abundance
51 …
Run Code Online (Sandbox Code Playgroud)

r unique plyr

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

包'ggplot2'不适用于R版本3.5.1

我无法安装ggp​​lot或ggplot2.我收到这条消息:

install.packages("ggplot2")

Installing package into ‘C:/Users/Tori/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
Warning: unable to access index for repository https://cran.revolutionanalytics.com/src/contrib:
  cannot open destfile 'C:\Users\Tori\AppData\Local\Temp\Rtmp86X0fa\file3e7c476344e', reason 'No such file or directory'
Warning: unable to access index for repository https://www.stats.ox.ac.uk/pub/RWin/src/contrib:
  cannot open destfile 'C:\Users\Tori\AppData\Local\Temp\Rtmp86X0fa\file3e7c490b57', reason 'No such file or directory'
Error in gzfile(file, mode) : cannot open the connection
In addition: Warning messages:
1: package ‘ggplot2’ is not available (for R version 3.5.1) 
2: In gzfile(file, mode) :
  cannot open compressed file 'C:\Users\Tori\AppData\Local\Temp\Rtmp86X0fa/libloc_185_a25398df.rds', probable …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

R:将向量转换为参数列表

我想将函数应用于向量。但是,该函数需要一系列参数。因此,我需要将向量“拆分”为不相关的参数。

假设我有一个名为dta的数据框。我想运行一个函数,例如在其列之一上运行平均值,例如 DV。

下图显示了问题所在

call("mean", dta$DV)
Run Code Online (Sandbox Code Playgroud)

回报

mean(c(0.371, -0.860, etc... ))
Run Code Online (Sandbox Code Playgroud)

该列是向量这一事实与函数mean不兼容,该函数需要一系列参数,而不是组合。

如果“mean”被替换为包含字符串的变量,则该解决方案应该有效,例如

fun <- "mean"

call( fun, dta$DV)
Run Code Online (Sandbox Code Playgroud)

r

4
推荐指数
1
解决办法
1312
查看次数

如何在 r 的多个特定列中使用 gsub

你能帮我回答一下这个小问题吗?

我有像下面这样的 data.frame 。比,

我想轻松使用 data.frame 中的 gsub 函数特定列

因为改变的角色是一样的!但我想更改很多特定的列。

在示例代码中,它只有 4 列,但我的数据有超过 10 列,我想更改 6~7 特定列(不连续)。

并更改相同的文本...

请帮忙谢谢

我正在这样做

data$col1<-gsub("sfsdf", "Hi", data$col1)
data$col3<-gsub("sfsdf", "Hi", data$col3)
data$col4<-gsub("sfsdf", "Hi", data$col4)
Run Code Online (Sandbox Code Playgroud)

等等...

专栏太多了...

col1 <- 1:10   
col2 <- 21:30   
col3 <- c("503.90", "303.90 obs", "803.90sfsdf sf", "203.90 obs", "303.90", "103.90 obs", "303.90", "403.90 obs", "803.90sfsdf sf", "303.90 obs")   
col4 <- c("303.90", "303.90 obs", "303.90", "203.90 obs", "303.90", "107.40fghfg", "303.90", "303.90 obs", "303.90", "303.90 obs")

data <- data.frame(col1, col2, col3, col4)

data$col3 <- …
Run Code Online (Sandbox Code Playgroud)

r

4
推荐指数
1
解决办法
8370
查看次数

R:当x明显在y时,grep返回0(我没有检查空格)

我明显错过了grep返回0的东西,当我'greping'一词显然是在'grepped'字符串中时:

在这个例子中,我正在检查字符串x是否在字符串y中:

x
[1] "c.3963+1G>T"

y
[1] "c.3963+1G>T"

grep(x, y)
integer(0)

x == y
[1] TRUE
Run Code Online (Sandbox Code Playgroud)

这些字符串是由我在矢量上做的一系列strsplits制成的.有什么理由可以看到这种行为,即使x明显在y中,grep也会返回0(并且它们甚至在本例中被认为是等效的)?

string grep r mismatch

3
推荐指数
2
解决办法
126
查看次数

包'tidyverse'不可用

我正在尝试安装"tidyverse",我得到以下错误.

install.packages("tidyverse")

package ‘tidyverse’ is available as a source package but not as a binary

Warning in install.packages :
  package ‘tidyverse’ is not available (as a binary package for R version 3.1.3)
Run Code Online (Sandbox Code Playgroud)

以下是我的会议的详细信息.

sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.12.1 (unknown)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
[1] tools_3.1.3
Run Code Online (Sandbox Code Playgroud)

有谁不知道这里缺少什么?

谢谢.

r tidyverse

3
推荐指数
1
解决办法
6876
查看次数

循环以动态填充数据框 R

我正在运行 for 循环来动态填充数据框(我知道小海豹死在某处,因为我使用的是 for 循环)

我有这样的想法(5 是返回标量的函数的占位符):

results<-data.frame(matrix(NA, nrow = length(seq(1:10)), ncol = 
length(seq(1:10))))
rows<-data.frame(matrix(NA, nrow = 1, ncol = 1))
for (j in seq(1:10)){
rows<-data.frame()
for (i in seq(1:10)){
   rows<-cbind(rows,5)
}
results<-cbind(results,rows)
}
Run Code Online (Sandbox Code Playgroud)

我使用上述方法收到以下错误消息。

Error in match.names(clabs, names(xi)) : 
names do not match previous names
Run Code Online (Sandbox Code Playgroud)

有更容易的方法吗?

loops r dataframe

3
推荐指数
1
解决办法
5187
查看次数

R计算分位数错误或不同?

我发现一篇文章提供了计算分位数的算法,而 R 显然没有遵循该文章。

文章为: https://www-users.york.ac.uk/~mb55/intro/quantile.htm

在 R 中,我有以下代码:

nv<-c(10,20,30,40)
quantile(nv)
  0%  25%  50%  75% 100% 
10.0 17.5 25.0 32.5 40.0
Run Code Online (Sandbox Code Playgroud)

然而,75%结果的分位数似乎是错误的,根据文章,公式是:

i = q(n+1) 
Run Code Online (Sandbox Code Playgroud)

在我的例子中(75%)q=0.75 且 n=4(我的组合中有 4 个观察值)

X_j + (X_j+1 - X_j) times (i - j) 
Run Code Online (Sandbox Code Playgroud)

这意味着它应该是:

30 + (40-30)*(3.75-3) = 37.5而不是32.5

我很难认为 R 犯了一个错误。

我在这里缺少什么?

谢谢。

r quantile

3
推荐指数
1
解决办法
2188
查看次数

如何使用 geom_bar 创建facet_wrap 图,其中包含所有变量及其灰色条形和其他颜色的特定变量?

我有一个数据框:

df1 <- data.frame(place = c("a", "a", "b", "b", "c", "c", "d", "d", "e", "e", "f", "f", "g", "g", 
                         "h", "h", "i", "i", "j", "j", "k", "k", "l", "l", "m", "m", "n", 
                         "n", "o", "o", "p", "p", "q", "q"), 
               cost_other = c("cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings",
                            "cost_savings", "other_savings"), 
               values = c(1.8,0.55, 0.836, 1.06, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 facet-wrap geom-bar

3
推荐指数
1
解决办法
42
查看次数

标签 统计

r ×10

ggplot2 ×2

dataframe ×1

facet-wrap ×1

geom-bar ×1

grep ×1

loops ×1

mismatch ×1

plyr ×1

quantile ×1

string ×1

tidyverse ×1

unique ×1