我正在使用R并且需要选择年龄(死亡年龄)小于或等于laclen(哺乳期长度)的行.我试图创建一个新的数据框,只包含行/ ids,其中column'aged'的值小于其对应的'laclength'值.
df:
id1 id2 laclen aged
9830 64526 26 6
7609 64547 28 0
9925 64551 3 0
9922 64551 3 5
9916 64551 3 8
9917 64551 3 8
9914 64551 3 2
Run Code Online (Sandbox Code Playgroud)
新数据框应如下所示:
dfnew:
id1 id2 laclen aged
9830 64526 26 6
7609 64547 28 0
9925 64551 3 0
9914 64551 3 2
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!
Bazon
比方说,我有这样的数据:
data <- c(1,2,3,4,5,6,NaN,5,9,NaN,23,9)
attr(data,"dim") <- c(6,2)
data
[,1] [,2]
[1,] 1 NaN
[2,] 2 5
[3,] 3 9
[4,] 4 NaN
[5,] 5 23
[6,] 6 9
Run Code Online (Sandbox Code Playgroud)
现在我想要删除其中包含NaN值的行:第1行和第4行.但我不知道这些行在哪里,如果它是100.000+行的数据集,所以我需要找到它们的函数并删除完整的一行.
任何人都能指出我正确的方向吗?
我想循环一个情节并将情节的结果放在一个PDF.
以下代码用于执行此操作:
这样做是循环3次,并从虹膜数据集绘制3个不同的图.然后它应该将其保存到C:/驱动器.该PDF文件被创建,但已损坏.
for(i in 1:3){
pdf(paste("c:/", i, ".pdf", sep=""))
plot(cbind(iris[1], iris[i]))
dev.off()
}
Run Code Online (Sandbox Code Playgroud) 当我创建直方图时,它看起来很像这样:
set.seed(1)
x <- 1:100
y <- x + rnorm(50)
y=round(y)
hist(y)
Run Code Online (Sandbox Code Playgroud)
有没有办法让直方图看起来像这样?我只能得到一个带有箱子的直方图,这对我的情节来说并不需要.

我不想要黑色垃圾箱,我实际上只想要蓝色,绿色和红色线条.stackoverflow能指向正确的方向吗?
假设我有2个级别的数据帧.LC和HC.现在我希望在彼此之上得到2个如下图.
data <- data.frame(
welltype=c("LC","LC","LC","LC","LC","HC","HC","HC","HC","HC"),
value=c(1,2,1,2,1,5,4,5,4,5))
Run Code Online (Sandbox Code Playgroud)
得到以下plot =的代码
x <- rnorm(1000)
y <- hist(x)
plot(y$breaks,
c(y$counts,0),
type="s",col="blue")
Run Code Online (Sandbox Code Playgroud)
(感谢Joris Meys)
那么,我怎么开始这个呢.因为我已经习惯了java,所以我想到了for循环,但是我被告知不要这样做.

我需要一个好的错误栏功能.
我已经尝试了包(心理),但在这里我无法删除x轴,我也尝试了包(ggplot2)但在这里我不能使用第二个y轴.任何人都可以推荐我在R中制作错误栏的好方法吗?
我正在尝试创建一个包含多个错误栏的条形图.像这样:http://flyordie.sin.khk.be/r/histogram%20error%20bars.PNG 我有以下数据集:http: //flyordie.sin.khk.be/r/output.csv
我尝试过使用ggplot2和格子图形,但没有找到任何适合我需要的东西.
我目前显示条形图的代码是:
data <- read.csv("c:/output.csv")
data
par(las=3)
barplot(data$PlateId,
height=data$HC.Maximum,
names.arg=data$PlateId,
col="lightblue")
Run Code Online (Sandbox Code Playgroud)
并显示最高的错误栏我使用此代码库(ggplot2)
limits <- aes(ymax = qc$HC.Maximum, ymin = qc$HC.Minimum)
p <- ggplot(qc, aes(colour=HC.Median,x=PlateId))
p + geom_bar(position="dodge")+ geom_errorbar(limits,position="dodge")
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将它们放在同一图形上(如我的例子)
数据:
qc <- structure(list(row = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Row", class = "factor"),
ID = 1:14, PlateId = c(35276L, 35279L, 35280L, 35281L, 35282L,
35290L, 35291L, 35292L, 35293L, 35294L, 35295L, 35296L, 35297L, …Run Code Online (Sandbox Code Playgroud) 我有这个问题.我有一个热图,(但我想这适用于每个情节)但我需要镜像我的y轴.
我在这里得到了一些示例代码:
library(gstat)
x <- seq(1,50,length=50)
y <- seq(1,50,length=50)
z <- rnorm(1000)
df <- data.frame(x=x,y=y,z=z)
image(df,col=heat.colors(256))
Run Code Online (Sandbox Code Playgroud)
这将生成以下热图
但我需要y轴镜像.从顶部的0和底部的50开始.有没有人知道我必须做些什么才能改变这个?

我正在尝试生成一些水平图的格子.现在我有2个问题.这是一些采样数据
library(lattice)
require(stats)
attach(environmental)
ozo.m <- loess((ozone^(1/3)) ~ wind * temperature * radiation,
parametric = c("radiation", "wind"), span = 1, degree = 2)
w.marginal <- seq(min(wind), max(wind), length.out = 50)
t.marginal <- seq(min(temperature), max(temperature), length.out = 50)
r.marginal <- seq(min(radiation), max(radiation), length.out = 4)
wtr.marginal <- list(wind = w.marginal, temperature = t.marginal,
radiation = r.marginal)
grid <- expand.grid(wtr.marginal)
grid[, "fit"] <- c(predict(ozo.m, grid))
levelplot(fit ~ wind * temperature | radiation, data = grid,
cuts = 10, region = TRUE,
xlab …Run Code Online (Sandbox Code Playgroud) 我正在研究我的情节的一些细节,我发现了一个我无法解决的问题.在我的levelplot上是数字标记.现在我想将y轴上的刻度线更改为相应的字母.(即1 = A,5 = E,27 = AA,29 = AC,......)
我已经习惯了
scales=list(
y=list(alternating=3,labels=toupper(c(letters[1],letters[5],letters[10],letters[15])))))
Run Code Online (Sandbox Code Playgroud)
但我希望它们根据Y轴上的内容而改变,而不是根据我给出的值.有人可以帮我这个吗?
levelplot(volcano,main="levelplot(volcano)")
Run Code Online (Sandbox Code Playgroud)
