是否有一个功能或命令,R这可以清除所有的global environment,就像clear在Matlab。rm如果我想删除它,我只知道需要我将每个变量名放入其中的函数。那真的不方便。
谢谢
我想为多列中的多个值提取一些摘要统计信息.我的数据如下
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) 我无法安装ggplot或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) 我想将函数应用于向量。但是,该函数需要一系列参数。因此,我需要将向量“拆分”为不相关的参数。
假设我有一个名为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) 你能帮我回答一下这个小问题吗?
我有像下面这样的 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) 我明显错过了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(并且它们甚至在本例中被认为是等效的)?
我正在尝试安装"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)
有谁不知道这里缺少什么?
谢谢.
我正在运行 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)
有更容易的方法吗?
我发现一篇文章提供了计算分位数的算法,而 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 犯了一个错误。
我在这里缺少什么?
谢谢。
我有一个数据框:
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)