The S language’s power is not its data management capability nor is data management the intent of the S language. However, often times when evaluating the output of a model you may need to perform basic data management with R/SPlus and you will find the S language acceptable in this role. The commands will seem more similar to Unix/Linux than SQL. However, the S language has many of the benefits of Unix/Linux (a concise language for data management) while being more data centric (allowing meta data for dataframes which includes column names). |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Example: | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
SELECT |
|||||||||||||||||||||||||||||||||||||||||
customer
|
|
||||||||||||||||||||||||||||||||||||||||
ORDER BY |
|||||||||||||||||||||||||||||||||||||||||
customer[order(customer[,2]),]
|
|
||||||||||||||||||||||||||||||||||||||||
WHERE |
|||||||||||||||||||||||||||||||||||||||||
subset(customer, custid == 5 )
|
|
||||||||||||||||||||||||||||||||||||||||
INNER JOIN |
|||||||||||||||||||||||||||||||||||||||||
merge (purchaseorder, customer, by.x = custid , by.y = custid , all = FALSE )
|
|
||||||||||||||||||||||||||||||||||||||||
LEFT OUTER JOIN |
|||||||||||||||||||||||||||||||||||||||||
merge (purchaseorder, customer, by.x = custid , by.y = custid , all = TRUE )
|
|
||||||||||||||||||||||||||||||||||||||||
GROUP BY |
|||||||||||||||||||||||||||||||||||||||||
Cust_sum <- merge (purchaseorder, customer, by.x = custid , by.y = custid , all = FALSE ) xtabs( ~ fname, cust_sum)
|
|
||||||||||||||||||||||||||||||||||||||||
UPDATE |
|||||||||||||||||||||||||||||||||||||||||
customer[1,]$age <-23
|
|
||||||||||||||||||||||||||||||||||||||||
INSERT |
|||||||||||||||||||||||||||||||||||||||||
newcust <- data.frame(custid = 6, fname = Terry , age =50) rbind(newcust,customer)
|
|
||||||||||||||||||||||||||||||||||||||||
DELETE |
|||||||||||||||||||||||||||||||||||||||||
subset(customer, custid != 1 )
|
|