I´m currently working with a 2 Data frames one that I simply call Data and another one called DataOutput. Data has over 400 thousand observations of 21 variables and and DataOutput only has 4 observations of 21 variables. DataOutput is a dataframe that includes for different sums simply how many NA and OOR(OutofRange) and #Measurements and Ratio((NA+OOR)/#Measurements). The Data dataframe currently holds a lot of columns that only include NA because there where simply no measurements of those variables.
I want to get rid of the columns that only have NA in them.
for(z in 2:22)
{
if(DataOutput[4,z] == 1) //This is the ratio ((NA+OOR)/#Measurements) == 1
{
Data <- subset(Data, select = -Data[,z] )
}
}
I tried to do this like this but it does not work. I cant simply hard code the columns I need to delete like select = - c(a,b) or something because the code has to work with many different same sized data frames. They all have different columns that are completely un available.
Any Ideas? Help is really appreciated!
> dput(head(Data))
structure(list(StartTime = structure(c(1169218200, 1169218800,
1169219400, 1169220000, 1169220600, 1169221200), class = c("POSIXct",
"POSIXt"), tzone = ""), Latitude = c(15.6383658333333, 15.648397,
15.6581663333333, 15.6680338333333, 15.6778031666667, 15.6876706666667
), Longitude = c(15.8445643333333, 15.8549853333333, 15.8651343333333,
15.8753853333333, 15.8855343333333, 15.8957853333333), GPSSpeed = c(NA,
NA, 315, 315, 315, 315), LogSpeed = c(NA, NA, 696.091532743333,
697.291378813333, 698.491512383334, 699.691533736667), WindSpeedRel = c(NA,
NA, 1.03611152968314, 1.00016348803882, 1.06045149695061, 0.995509934806929
), WindDirRel = c(NA, NA, 1.38425886694239, 1.29982376776468,
1.37160349066357, 1.33137136705896), Course = c(NA, NA, NA, NA,
NA, NA), SeaDepth = c(NA, NA, NA, NA, NA, NA), DraftFWD = c(NA,
NA, NA, NA, NA, NA), DraftAFT = c(NA, NA, NA, NA, NA, NA), Rudder = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), PropellerKW = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), MEConsumption = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), MERPM = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), MELoad = c(NA,
NA, NA, NA, NA, NA), DGConsumption = c(NA, NA, NA, NA, NA, NA
), DG1_Load = c(NA, NA, NA, NA, NA, NA), DG2_Load = c(NA, NA,
NA, NA, NA, NA), DG3_Load = c(NA, NA, NA, NA, NA, NA), DG4_Load = c(NA,
NA, NA, NA, NA, NA), DG5_Load = c(NA, NA, NA, NA, NA, NA)), .Names = c("StartTime",
"Latitude", "Longitude", "GPSSpeed", "LogSpeed", "WindSpeedRel",
"WindDirRel", "Course", "SeaDepth", "DraftFWD", "DraftAFT", "Rudder",
"PropellerKW", "MEConsumption", "MERPM", "MELoad", "DGConsumption",
"DG1_Load", "DG2_Load", "DG3_Load", "DG4_Load", "DG5_Load"), row.names = c(NA,
6L), class = "data.frame")
and
> dput(head(DataOutput))
structure(list(Type = structure(c(1L, 3L, 2L, 4L), .Label = c("#Measurements",
"NA", "OOR", "Ratio((NA+OOR)/#M"), class = "factor"), Latitude = c(67879,
0, 19829, 0.292122747830699), Longitude = c(67879, 0, 19829,
0.292122747830699), GPSSpeed = c(67879, 7, 19904, 0.293330779769885
), LogSpeed = c(67879, 18235, 49621, 0.999661161773155), WindSpeedRel = c(67879,
392, 38297, 0.569970093843457), WindDirRel = c(67879, 0, 38297,
0.564195111890275), Course = c(67879, 0, 67879, 1), SeaDepth = c(67879,
0, 67879, 1), DraftFWD = c(67879, 0, 67879, 1), DraftAFT = c(67879,
0, 67879, 1), Rudder = c(67879, 46675, 21204, 1), PropellerKW = c(67879,
5857, 21332, 0.400550980421043), MEConsumption = c(67879, 10,
21185, 0.312246792085918), MERPM = c(67879, 5105, 22030, 0.399755447192799
), MELoad = c(67879, 0, 67879, 1), DGConsumption = c(67879, 0,
67879, 1), DG1_Load = c(67879, 0, 67879, 1), DG2_Load = c(67879,
0, 67879, 1), DG3_Load = c(67879, 0, 67879, 1), DG4_Load = c(67879,
0, 67879, 1), DG5_Load = c(67879, 0, 67879, 1)), .Names = c("Type",
"Latitude", "Longitude", "GPSSpeed", "LogSpeed", "WindSpeedRel",
"WindDirRel", "Course", "SeaDepth", "DraftFWD", "DraftAFT", "Rudder",
"PropellerKW", "MEConsumption", "MERPM", "MELoad", "DGConsumption",
"DG1_Load", "DG2_Load", "DG3_Load", "DG4_Load", "DG5_Load"), row.names = c(NA,
4L), class = "data.frame")