仅供参考,我是使用 R 的新手,所以我的代码可能很笨重。我已经完成了这方面的功课,但无法为 R 找到“除外”逻辑运算符,并且在我的代码中确实需要类似的东西。我的输入数据是一个 .csv,其中包含 12 列和 1440 行的整数和空值。
oneDayData <- read.csv("data.csv") # Loading data
oneDayMatrix <- data.matrix(oneDayData, rownames.force = NA) #turning data frame into a matrix
rowBefore <- data.frame(oneDayData[i-1,10], stringsAsFactors=FALSE) # Creating a variable to be used in the if statement, represents cell before the cell in the loop
ctr <- 0 # creating a counter and zeroing it
for (i in 1:nrow(oneDayMatrix)) {
if ((oneDayMatrix[i,10] == -180) & (oneDayMatrix[i,4] == 0)) { # Makes sure that there is missing data matched with a zero in activityIn
impute1 <- replace(oneDayMatrix[ ,10], oneDayMatrix[i,10], rowBefore)
ctr <- (ctr + 1) # Populating the counter with how many rows get changed
}
else{
print("No data fit this criteria.")
}
}
print(paste(ctr, "rows have been changed.")) # Printing the counter and number of rows that got changed enter code here
我想在我的 if 语句或等效语句中添加某种 EXCEPT 条件,例如:使用前面的两个条件(查看代码中的 if 语句)除了 oneDayMatrix[i-1, 4] > 0 时除外。我真的很感激对此有任何帮助,并在此先感谢您!