Nrowchips sumchipswidth 32

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: th R and SQL. •  The WHERE clause can also be used with other Boolean operators. The keyword NOT negates a condi;on, and parentheses can be used to clarify order of evalua;on. SELECT * FROM chips WHERE date > 1990;! SELECT * FROM chips WHERE NOT width = 8;! SELECT * FROM chips WHERE NOT (width = 8 OR width = 16);! •  In both R and SQL, we can do both types of subse^ng at once. •  R: chips[chips$processor == ‘Pentium’ |! ! !chips$processor == ‘PentiumII’, ! c(‘mips’, ‘microns’)]! •  SQL: SELECT mips, microns FROM chips! WHERE processor = ‘Pentium’ OR ! processor = ‘PentiumII’;! General Syntax SELECT a>ribute(s) FROM table(s) [WHERE constraints]; [op;onal] How would we pull the years of all 32- bit processors that execute fewer than 250 million instruc;ons per second (mips), 1) in R, chips[ chips$mips < 250 & chips$width == 32, ! “date”]! 2) in SQL? SELECT date FROM chips ! WHERE mips < 250 AND width = 32;! SQL offers limited features for summarizing data - - some aggregate func;ons that operate over the rows of a table, and some mathema;cal func;ons that operate on individual values in a row. The aggregate func;ons are •  COUNT - number of rows •  SUM - total of all values for an a>ribute •  AVG - average value for an a>ribute •  MIN - minimum value for an a>ribute •  MAX - maximum value for an a>ribute SELECT a>ribute(s) FROM table(s) [WHERE constraints]; can also be func+ons of a>ributes Exercise: 1)  How many rows are in the chips table? SELECT COUNT(date) FROM chips;! 2) How many chips have a>ribute width equal to 32? SELECT COUNT(date) FROM chips WHERE width = 32;! 3) What is the average clock speed for the chips in ques;on 2? SELECT AVG(clockspeed) FROM chips WHERE width = 32;! Now answer the same ques;ons assuming chips is a data frame in R. nrow(chips); !! sum(chips$width == 32); ! mean(chips$clockspeed[chips$wi...
View Full Document

This document was uploaded on 02/16/2014 for the course STATISTICS 3026 at Columbia.

Ask a homework question - tutors are online