Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Let us suppose I am using this built-in dataset to draw up a
- # shortlist of where I might wish to go on holiday
- df <- data.frame(state.x77);
- # pp - define a task-specific pretty print function
- pp <- function(row) {
- print(row); # Example dataset is simple enough to just print the entire row
- }
- # cls - clear the screen (this hack works on Windows but I've commented it for now)
- cls <- function() {
- #system("powershell -ExecutionPolicy Bypass -command (New-Object -ComObject Wscript.Shell).SendKeys([string][char]12)");
- }
- # It would halve the number of keystrokes needed if I knew a way to read
- # a single character
- readcharacter <- readline;
- sift <- function(df, pp)
- {
- classification = rep('', nrow(df));
- for (nRow in 1:nrow(df))
- {
- cls();
- pp(df[nRow,]);
- cat("nEnter 'a' to discard, 'd' to keep, 'q' to quitn");
- char <- '';
- while (char != 'a' && char != 'd' && char != 'q') {
- char <- readcharacter();
- }
- if (char == 'q')
- break;
- classification[nRow] = char;
- }
- return(cbind(df,classification=classification));
- }
- result = sift(df, pp);
- cls();
- cat("Shortlist:n");
- print(row.names(result[result$classification=='d',]));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement