我想从数据帧的str输出中提取一些信息.
试过这个......
> tmp <- str(iris)
> tmp
NULL
Run Code Online (Sandbox Code Playgroud)
是否可以将其存储在变量中?
如何在下面的ggplot中提取用于标记y轴和x轴的数字(分别20, 30, 40和10 , 15 ,20 ,25, 30, 35)?
情节
可重现的代码
# Scatterplot
theme_set(theme_bw()) # pre-set the bw theme.
g <- ggplot(mpg, aes(cty, hwy))
g + geom_count(col="tomato3", show.legend=F) +
labs(subtitle="mpg: city vs highway mileage",
y="hwy",
x="cty",
title="Counts Plot")
Run Code Online (Sandbox Code Playgroud)
我已经尝试查看输出str(g),但是成功了.
我有一个像这样的嵌套列表:
smth <- list()
smth$a <- list(a1=1, a2=2, a3=3)
smth$b <- list(b1=4, b2=5, b3=6)
smth$c <- "C"
Run Code Online (Sandbox Code Playgroud)
列表中每个元素的名称都是唯一的。
我想仅通过名称从这样的列表中获取元素,而不知道它位于哪里。
例子:
getByName(smth, "c")=“C”
getByName(smth, "b2")= 5
另外,我真的不想使用,unlist因为真正的列表中有很多重元素。