I'm new to R so I don't know all the ins and outs of it yet, but I think the code should work. It's supposed to look through a matrix of people with different heights, weights, and income levels read from a .csv file, then remove any rows that have any value as NA or that have any value not within a certain given range (e.g. 4.5 to 6.5 for height). When I run the script some people are removed but there are still people with NA values or values outside of the given ranges, so I don't know if it's removing only a certain amount of the people that don't fit or if it's removing the wrong people completely, or both.
original = read.csv("C:/Users/gsbal/OneDrive/Documents/Quants R Course/HW/A2-C-DirtyData.csv")
nums = 1:nrow(original)
toDelete = 0
deleted = 0
for (i in nums)
{
na = is.na(original[i, 1]) | is.na(original[i, 2]) | is.na(original[i, 3])
if (na == T)
{
toDelete = i - deleted
original = original[-toDelete,]
deleted = deleted + 1
}
}
nums = 1:nrow(original)
toDelete = 0
deleted = 0
for (i in nums)
{
height = original[i, 1] < 4.5 | original[i, 1] > 6.5
if (height == T)
{
toDelete = i - deleted
original = original[-toDelete,]
deleted = deleted + 1
}
}