我有一个包含大量对象的工作区,我想除去一个以外的所有对象.理想情况下,我想避免打字rm(obj.1, obj.2... obj.n).有可能表明 remove all objects but these ones吗?
我想在R中叠加两个散点图,使得每组点具有其自己的(不同的)y轴(即,在图中的位置2和4),但是这些点看起来叠加在同一图上.
有可能这样做plot吗?
编辑显示问题的示例代码
# example code for SO question
y1 <- rnorm(10, 100, 20)
y2 <- rnorm(10, 1, 1)
x <- 1:10
# in this plot y2 is plotted on what is clearly an inappropriate scale
plot(y1 ~ x, ylim = c(-1, 150))
points(y2 ~ x, pch = 2)
Run Code Online (Sandbox Code Playgroud) 在R数据帧编码的下面,我想更换所有时代B
与出现b.
junk <- data.frame(x <- rep(LETTERS[1:4], 3), y <- letters[1:12])
colnames(junk) <- c("nm", "val")
Run Code Online (Sandbox Code Playgroud)
这提供:
nm val
1 A a
2 B b
3 C c
4 D d
5 A e
6 B f
7 C g
8 D h
9 A i
10 B j
11 C k
12 D l
Run Code Online (Sandbox Code Playgroud)
我最初的尝试是使用for和if语句,像这样:
for(i in junk$nm) if(i %in% "B") junk$nm <- "b"
Run Code Online (Sandbox Code Playgroud)
但我相信你可以看到,这个替换所有的值junk$nm用b.我可以看到为什么这样做但我似乎无法让它只替换原始值为的那些垃圾$ nm的情况B.
注意:我设法解决了问题 …
我想将现有数据框的列中的值转换为行名称.是否可以在不导出数据帧然后通过row.names =调用重新导入数据帧的情况下执行此操作?
例如,我想转换:
> samp
names Var.1 Var.2 Var.3
1 A 1 5 0
2 B 2 4 1
3 C 3 3 2
4 D 4 2 3
5 E 5 1 4
Run Code Online (Sandbox Code Playgroud)
成:
> samp.with.rownames
Var.1 Var.2 Var.3
A 1 5 0
B 2 4 1
C 3 3 2
D 4 2 3
E 5 1 4
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在使用以下代码在R中创建一个boxplot:
boxplot(perc.OM.y ~ Depth, axes = F, ylim = c(-0.6, 0.2), xlim = c(3.5, 5.5),
lwd = 0.1, col = 8,
ylab = "Loss of Percent Organic Matter per Year", cex.lab = 1.5)
axis(1, at = c(3.5, 4, 5, 5.5), labels = c(" ", "Shallow", "Deep", " "),
cex.axis = 1.5)
axis(2, cex.axis = 1.5)
Run Code Online (Sandbox Code Playgroud)
问题是y轴上的数字标签当前与轴标题重叠.有没有办法在轴标题和轴号标签之间放置更多空间?
谢谢
我有一个图像文件的目录foo_0.jpg来foo_99.jpg.我想foo_0.jpg通过复制文件foo_54.jpg.
这可能只是使用bash通配符吗?
我想是这样cp foo_[0-54].jpg,但我知道这个选择0-5和4(右?)
此外,如果只有通配符不可能(或有效),那么更好的方法是什么?
谢谢.
我正在写一个测验html,我想在问题之间插入一致的空白垂直空间(就像vspace{3 cm}在LaTeX中使用的那样).
例如:
<html>
<body>
<p>
This is the first question?
<!-- this is where I want about 3 cm of space -->
</p>
<p>
This is the second question?
<!-- this is where I want about 3 cm of space -->
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
是否有直接的方式使用just html和css?
我想在R中创建一个数据帧的子集,它基于一列因子中的一个或另一个值,但似乎我不能使用|因子值.
例:
# fake data
x <- sample(1:100, 9)
nm <- c("a", "a", "a", "b", "b", "b", "c", "c", "c")
fake <- cbind(as.data.frame(nm), as.data.frame(x))
# subset fake to only rows with name equal to a or b
fake.trunk <- fake[fake$nm == "a" | "b", ]
Run Code Online (Sandbox Code Playgroud)
产生错误:
Error in fake$nm == "a" | "b" :
operations are possible only for numeric, logical or complex types
Run Code Online (Sandbox Code Playgroud)
我怎么能做到这一点?
显然,我的实际数据框在因子列中有超过3个值,因此仅使用!= "c"它将不起作用.
plot在R中使用会导致x轴上的因子按字母顺序排列.
如何在x轴上指定因子的顺序?
例:
y <- 1:9
x <- c(rep("B", 3), rep("A", 3), rep("C", 3))
plot(y ~ as.factor(x))
Run Code Online (Sandbox Code Playgroud)
这导致:

如何将其绘制为"B","A","C"?
使用str(survey_OM)我的数据帧上表明我所有的数值数据为atomic.如果我使用class(survey_OM$perc.OM)它返回numeric.
我一直认为第二列str显示了数据类,但它看起来并不那么简单...所以我的问题是:
str报告是什么?atomic它与什么有什么不同numeric?atomic,不num还是int?谢谢.
dput(head(survey_OM, 20))规定:
> dput(head(survey_OM, 20))
structure(list(lake = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("E-2",
"E-4", "E pond", "EX 1", "GTH 110", "GTH 112", "GTH 114", "GTH 156",
"GTH 91", "GTH 98", "N-1", "NE-10", "NE-11", "NE-3", "NE-8", …Run Code Online (Sandbox Code Playgroud)