参考までに、私は R を使用するのが初めてなので、私のコードはおそらくかなり不格好です。私はこれについて宿題をしましたが、R の "Except" 論理演算子を見つけることができず、コードにそのようなものが本当に必要です。私の入力データは、12 列と 1440 行の整数と null 値を含む .csv です。
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 条件を追加したいと思います: oneDayMatrix[i-1, 4] > 0 の場合、前の 2 つの条件を使用します (コード内の if ステートメントを参照)。これについて何か助けがあれば、事前に感謝します!