rstudio - R: Filling the NULLs in a data column -


the data i'm working on looks this:

          timestamp switchonoff speed speedlimit 2015-03-26 20:00:00        null  null         35 2015-03-26 20:15:00        null    41         35 2015-03-26 20:30:00           0    49         35 2015-03-26 20:45:00           1  null         35 2015-03-26 21:00:00         yes  null       null 2015-03-26 21:15:00        null  null         35 2015-03-26 21:30:00          no  null       null 2015-03-26 21:45:00           5    51         40 

for variable: switchonoff: 0, 1;
-but has many other levels i'm trying covert 0, 1 only. tried following for-loop, not work because of nulls (empty, length = 0):

for (i in 1:length(timestamp)) {   if (is.null(switchonoff[i]) | switchonoff[i] == "yes") {     switchonoff[i] = 1   } else if (switchonoff[i] == "no") {       switchonoff[i] = 0   } else if (switchonoff[i] >= 1){       switchonoff[i] = 1   } else {switchonoff[i] = switchonoff[i]} } 

so wondering if knows better way solving kind of null-filling problems? also, there way import data r without ignoring nulls data stay in exact position should? many thanks!

m


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -