我对R相当陌生,我试图将三块地块堆叠在一起研究每个地块彼此的多样性。作为R的新手,我仍然没有设法找到解决方案。我已经尝试了ggplot和多槽,但未能完成任务。也许我的文本文件中的标题是问题,或者我甚至没有看清问题!这将会有很大的帮助,如果任何人都可以在这方面告诉我..与R堆积地块
我的脚本如下:
defects <- read.table(file="C:/_____.txt",header=TRUE)
squareX <- c()
squareY <- c()
distance <- c(0, 17.0, 17.5, 34.5, 35.0, 52.0, 52.5, 69.5, 70.0, 87.0,
87.5, 104.5, 105.0, 122.0, 122.5, 139.5)
square_beginning <- distance[seq(1,length(distance),2)]
for (i in 1:length(defects$x)){
for (e in square_beginning){
if (defects$x[i]>e & defects$x[i]<e+17.5) {
squareX[i] <- e/17.5+1
}
if (defects$y[i]>e & defects$y[i]<e+17.5) {
squareY[i] <- e/17.5+1
}
}
}
defects<- cbind(defects,squareX,squareY)
#plot (defects)
cont <- read.table(file="C:/____.txt",header=TRUE)
squareX <- c()
squareY <- c()
distance <- c(0, 17.0, 17.5, 34.5, 35.0, 52.0, 52.5, 69.5, 70.0, 87.0,
87.5, 104.5, 105.0, 122.0, 122.5, 139.5)
square_beginning <- distance[seq(1,length(distance),2)]
for (i in 1:length(cont$x)){
for (e in square_beginning){
if (cont$x[i]>e & cont$x[i]<e+17.5) {
squareX[i] <- e/17.5+1
}
if (cont$y[i]>e & cont$y[i]<e+17.5) {
squareY[i] <- e/17.5+1
}
}
}
par(mo=c(1,2))
plot(defects, main="test 1")
plot(cont, main="test 2")
欢迎来到SO!您提供的脚本很好,但不幸的是它不可重现(例如缺少缺陷)。请参阅[如何制作可重现的示例](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)了解一些信息。如果您使其具有可重复性,那么您更有可能对您的问题得到快速,准确的答案。 – 2015-03-25 12:27:31