Subsetting, Sorting, and Summarizing Data in R

More practice for getting and cleaning data in R…

> set.seed(13435)
> X <- data.frame("var1"=sample(1:5),
                "var2"=sample(6:10),"var3"=sample(11:15))
> X
 var1 var2 var3
1   2    8   15
2   3    7   12
3   5    6   14
4   1   10   11
5   4    9   13

> X <- X[sample(1:5),]   ##Resampling of all 5 rows
> X
 var1 var2 var3
1   2    8   15
4   1   10   11
2   3    7   12
3   5    6   14
5   4    9   13

> X$var2[c(1,3)]=NA    
> X
 var1 var2 var3
1   2   NA   15
4   1   10   11
2   3   NA   12
3   5    6   14
5   4    9   13

> X[,1]             ##Subset 1st column ([row,col])
[1] 2 1 3 5 4

> X[,"var1"]        ##Subset 1st column by name
[1] 2 1 3 5 4

> X[1:2,"var2"]     ##Subset rows and columns simultaneously
[1] NA 10

> X[(X$var1<=3 & X$var3>11),]  ##Subset with AND
 var1 var2 var3
1   2   NA   15
2   3   NA   12

> X[(X$var1<=3 | X$var3>14),]  ##Subset with OR
 var1 var2 var3
1   2   NA   15
4   1   10   11
2   3   NA   12

> X[which(X$var2 > 8),]      ##Subset with WHICH to ignore NA's
 var1 var2 var3
4   1   10   11
5   4    9   13

> sort(X$var1)                    ##Sort ascending
[1] 1 2 3 4 5

> sort(X$var1,decreasing = TRUE)  ##Sort descending
[1] 5 4 3 2 1

> sort(X$var2,na.last = TRUE)     ##Sort with NA's at end
[1] 6 9 10 NA NA

> X[order(X$var1),]        ##Reorder by column
 var1 var2 var3
4   1   10   11
1   2   NA   15
2   3   NA   12
5   4    9   13
3   5    6   14

> X[order(X$var1,X$var3),] ##Reorder by multiple columns when duplicate values
 var1 var2 var3
4   1   10   11
1   2   NA   15
2   3   NA   12
5   4    9   13
3   5    6   14

> install.packages("plyr")
trying URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.3/plyr_1.8.4.tgz'
Content type 'application/x-gzip' length 805071 bytes (786 KB)
==================================================
downloaded 786 KB


The downloaded binary packages are in
 /var/folders/hp/83j66jw52cs83n68hkkvx24r0000gn/T//Rtmp9o0ZdT/downloaded_packages
> library(plyr)

> arrange(X,var1)    ##Arrange is another way to sort
 var1 var2 var3
1   1   10   11
2   2   NA   15
3   3   NA   12
4   4    9   13
5   5    6   14

> arrange(X,desc(var1))  ##Arrange descending
 var1 var2 var3
1   5    6   14
2   4    9   13
3   3   NA   12
4   2   NA   15
5   1   10   11

> X$var4 <- rnorm(5)    ##Create a new column
> X
 var1 var2 var3       var4
1   2   NA   15  0.1875960
4   1   10   11  1.7869764
2   3   NA   12  0.4966936
3   5    6   14  0.0631830
5   4    9   13 -0.5361329

> Y <- cbind(X,rnorm(5))     ##New column on right
> Y
 var1 var2 var3       var4    rnorm(5)
1   2   NA   15  0.1875960  0.62578490
4   1   10   11  1.7869764 -2.45083750
2   3   NA   12  0.4966936  0.08909424
3   5    6   14  0.0631830  0.47838570
5   4    9   13 -0.5361329  1.00053336

> Z <- cbind(rnorm(5),X)     ##New column on left
> Z
    rnorm(5) var1 var2 var3       var4
1  0.5439561    2   NA   15  0.1875960
4  0.3304796    1   10   11  1.7869764
2 -0.9710917    3   NA   12  0.4966936
3 -0.9446847    5    6   14  0.0631830
5 -0.2967423    4    9   13 -0.5361329

> J <- rbind(X,rnorm(5))     ##New row on bottom
> J
      var1       var2        var3       var4
1 2.000000         NA  15.0000000  0.1875960
4 1.000000 10.0000000  11.0000000  1.7869764
2 3.000000         NA  12.0000000  0.4966936
3 5.000000  6.0000000  14.0000000  0.0631830
5 4.000000  9.0000000  13.0000000 -0.5361329
6 1.149505 -0.8705105  -0.9870139  0.3262530

> K <- rbind(rnorm(5),X)     ##New row on top
> K
        var1       var2       var3       var4
1  -1.010516  0.6095613  0.5041528  1.3798872
11  2.000000         NA 15.0000000  0.1875960
4   1.000000 10.0000000 11.0000000  1.7869764
2   3.000000         NA 12.0000000  0.4966936
3   5.000000  6.0000000 14.0000000  0.0631830
5   4.000000  9.0000000 13.0000000 -0.5361329

 

Look at the data and try to identify any quirks, outliers, misspellings, inaccuracies, missing data, or anything weird that needs to be fixed before moving on to exploratory data analysis.

> fileUrl <- "https://data.baltimorecity.gov/api/views/k5ry-ef3g/rows.csv?accessType=DOWNLOAD"

> download.file(fileUrl,destfile = "./sampledata/restaurants.csv", method = "curl")
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0100 15881 0 15881 0 0 4401 0 --:--:-- 0:00:03 --:--:-- 4401100 15881 0 15881 0 0 4147 0 --:--:-- 0:00:03 --:--:-- 4147100 32249 0 32249 0 0 5766 0 --:--:-- 0:00:05 --:--:-- 5766100 32249 0 32249 0 0 5304 0 --:--:-- 0:00:06 --:--:-- 7073100 81385 0 81385 0 0 11266 0 --:--:-- 0:00:07 --:--:-- 14724100 81385 0 81385 0 0 10416 0 --:--:-- 0:00:07 --:--:-- 15577100 97769 0 97769 0 0 11027 0 --:--:-- 0:00:08 --:--:-- 16260100 109k 0 109k 0 0 12645 0 --:--:-- 0:00:08 --:--:-- 24393

> restData <- read.csv("./sampledata/restaurants.csv")

> head(restData,n=3)
 name zipCode neighborhood councilDistrict policeDistrict
1 410 21206 Frankford 2 NORTHEASTERN
2 1919 21231 Fells Point 1 SOUTHEASTERN
3 SAUTE 21224 Canton 1 SOUTHEASTERN
 Location.1
1 4509 BELAIR ROAD\nBaltimore, MD\n
2 1919 FLEET ST\nBaltimore, MD\n
3 2844 HUDSON ST\nBaltimore, MD\n

> tail(restData,n=3)
 name zipCode neighborhood councilDistrict policeDistrict
1325 ZINK'S CAF\u0090 21213 Belair-Edison 13 NORTHEASTERN
1326 ZISSIMOS BAR 21211 Hampden 7 NORTHERN
1327 ZORBAS 21224 Greektown 2 SOUTHEASTERN
 Location.1
1325 3300 LAWNVIEW AVE\nBaltimore, MD\n
1326 1023 36TH ST\nBaltimore, MD\n
1327 4710 EASTERN Ave\nBaltimore, MD\n

> summary(restData)           ##Notice the negative zipcode
 name zipCode neighborhood
 MCDONALD'S : 8 Min. :-21226 Downtown :128 
 POPEYES FAMOUS FRIED CHICKEN: 7 1st Qu.: 21202 Fells Point : 91 
 SUBWAY : 6 Median : 21218 Inner Harbor: 89 
 KENTUCKY FRIED CHICKEN : 5 Mean : 21185 Canton : 81 
 BURGER KING : 4 3rd Qu.: 21226 Federal Hill: 42 
 DUNKIN DONUTS : 4 Max. : 21287 Mount Vernon: 33 
 (Other) :1293 (Other) :863 
 councilDistrict policeDistrict Location.1 
 Min. : 1.000 SOUTHEASTERN:385 1101 RUSSELL ST\nBaltimore, MD\n: 9 
 1st Qu.: 2.000 CENTRAL :288 201 PRATT ST\nBaltimore, MD\n : 8 
 Median : 9.000 SOUTHERN :213 2400 BOSTON ST\nBaltimore, MD\n : 8 
 Mean : 7.191 NORTHERN :157 300 LIGHT ST\nBaltimore, MD\n : 5 
 3rd Qu.:11.000 NORTHEASTERN: 72 300 CHARLES ST\nBaltimore, MD\n : 4 
 Max. :14.000 EASTERN : 67 301 LIGHT ST\nBaltimore, MD\n : 4 
 (Other) :145 (Other) :1289 

> str(restData)
'data.frame': 1327 obs. of 6 variables:
 $ name : Factor w/ 1277 levels "#1 CHINESE KITCHEN",..: 9 3 992 1 2 4 5 6 7 8 ...
 $ zipCode : int 21206 21231 21224 21211 21223 21218 21205 21211 21205 21231 ...
 $ neighborhood : Factor w/ 173 levels "Abell","Arlington",..: 53 52 18 66 104 33 98 133 98 157 ...
 $ councilDistrict: int 2 1 1 14 9 14 13 7 13 1 ...
 $ policeDistrict : Factor w/ 9 levels "CENTRAL","EASTERN",..: 3 6 6 4 8 3 6 4 6 6 ...
 $ Location.1 : Factor w/ 1210 levels "1 BIDDLE ST\nBaltimore, MD\n",..: 835 334 554 755 492 537 505 530 507 569 ...

> quantile(restData$councilDistrict,na.rm = TRUE)
 0% 25% 50% 75% 100% 
 1 2 9 11 14 

> quantile(restData$councilDistrict,probs=c(0.5,0.75,0.9))
50% 75% 90% 
 9 11 12 

> table(restData$zipCode,useNA = "ifany")  ##Adds NA column and counts NA's if any

-21226 21201 21202 21205 21206 21207 21208 21209 21210 21211 
 1 136 201 27 30 4 1 8 23 41 
 21212 21213 21214 21215 21216 21217 21218 21220 21222 21223 
 28 31 17 54 10 32 69 1 7 56 
 21224 21225 21226 21227 21229 21230 21231 21234 21237 21239 
 199 19 18 4 13 156 127 7 1 3 
 21251 21287 
 2 1 

> table(restData$councilDistrict,restData$zipCode)
 
 -21226 21201 21202 21205 21206 21207 21208 21209 21210 21211 21212
 1 0 0 37 0 0 0 0 0 0 0 0
 2 0 0 0 3 27 0 0 0 0 0 0
 3 0 0 0 0 0 0 0 0 0 0 0
 4 0 0 0 0 0 0 0 0 0 0 27
 5 0 0 0 0 0 3 0 6 0 0 0
 6 0 0 0 0 0 0 0 1 19 0 0
 7 0 0 0 0 0 0 0 1 0 27 0
 8 0 0 0 0 0 1 0 0 0 0 0
 9 0 1 0 0 0 0 0 0 0 0 0
 10 1 0 1 0 0 0 0 0 0 0 0
 11 0 115 139 0 0 0 1 0 0 0 1
 12 0 20 24 4 0 0 0 0 0 0 0
 13 0 0 0 20 3 0 0 0 0 0 0
 14 0 0 0 0 0 0 0 0 4 14 0
 
 21213 21214 21215 21216 21217 21218 21220 21222 21223 21224 21225
 1 2 0 0 0 0 0 0 7 0 140 1
 2 0 0 0 0 0 0 0 0 0 54 0
 3 2 17 0 0 0 3 0 0 0 0 0
 4 0 0 0 0 0 0 0 0 0 0 0
 5 0 0 31 0 0 0 0 0 0 0 0
 6 0 0 15 1 0 0 0 0 0 0 0
 7 0 0 6 7 15 6 0 0 0 0 0
 8 0 0 0 0 0 0 0 0 2 0 0
 9 0 0 0 2 8 0 0 0 53 0 0
 10 0 0 0 0 0 0 1 0 0 0 18
 11 0 0 0 0 9 0 0 0 1 0 0
 12 13 0 0 0 0 26 0 0 0 0 0
 13 13 0 1 0 0 0 0 0 0 5 0
 14 1 0 1 0 0 34 0 0 0 0 0
 
 21226 21227 21229 21230 21231 21234 21237 21239 21251 21287
 1 0 0 0 1 124 0 0 0 0 0
 2 0 0 0 0 0 0 1 0 0 0
 3 0 1 0 0 0 7 0 0 2 0
 4 0 0 0 0 0 0 0 3 0 0
 5 0 0 0 0 0 0 0 0 0 0
 6 0 0 0 0 0 0 0 0 0 0
 7 0 0 0 0 0 0 0 0 0 0
 8 0 2 13 0 0 0 0 0 0 0
 9 0 0 0 11 0 0 0 0 0 0
 10 18 0 0 133 0 0 0 0 0 0
 11 0 0 0 11 0 0 0 0 0 0
 12 0 0 0 0 2 0 0 0 0 0
 13 0 1 0 0 1 0 0 0 0 1
 14 0 0 0 0 0 0 0 0 0 0

> sum(is.na(restData$councilDistrict))  ##Count missing data
[1] 0

> any(is.na(restData$councilDistrict))  ##Check if any NA's
[1] FALSE

> all(restData$zipCode > 0)     ##Check if all zipcodes are positive
[1] FALSE

> colSums(is.na(restData))     ##Count NA's for all columns
 name zipCode neighborhood councilDistrict 
 0 0 0 0 
 policeDistrict Location.1 
 0 0 

> all(colSums(is.na(restData))==0)  ##All columns free of missing data?
[1] TRUE

> table(restData$zipCode %in% c("21212")) ##Are there any zipcodes equal to "21212"

FALSE TRUE   ##Logical vector
 1299 28 

##Are there any values in the zipcode column that are either 21212 or 21213? 
> table(restData$zipCode %in% c("21212","21213")) 
FALSE TRUE 
 1268 59 

##The %in% operator becomes useful when subsetting lots of values from the logical vector
> restData[restData$zipCode %in% c("21212","21213"),]
 name zipCode
29 BAY ATLANTIC CLUB 21212
39 BERMUDA BAR 21213
92 ATWATER'S 21212
111 BALTIMORE ESTONIAN SOCIETY 21213
187 CAFE ZEN 21212
220 CERIELLO FINE FOODS 21212
266 CLIFTON PARK GOLF COURSE SNACK BAR 21213
276 CLUB HOUSE BAR & GRILL 21213
289 CLUBHOUSE BAR & GRILL 21213
291 COCKY LOU'S 21213
362 DREAM TAVERN, CARRIBEAN U.S.A. 21213
373 DUNKIN DONUTS 21212
383 EASTSIDE SPORTS SOCIAL CLUB 21213
417 FIELDS OLD TRAIL 21212
475 GRAND CRU 21212
545 RANDY'S BAR 21213
604 MURPHY'S NEIGHBORHOOD BAR & GRILL 21212
616 NEOPOL 21212
620 NEW CLUB THUNDERBIRD INC. 21213
626 NEW MAYFIELD, INC. 21213
678 IKAN SEAFOOD 21212
711 KAY-CEE CLUB 21212
763 LA'RAE 21213
777 LEMONGRASS BALTIMORE 21213
779 LEN'S SANDWICH SHOP 21213
845 MCDONALD'S 21213
852 MCDONALD'S 21212
873 NEW REX LIQUORS,INC. 21212
895 OK TAVERN 21213
919 PANERA BREAD 21212
940 PEIWEI ASIAN DINER 21212
949 PERGUSA ENTERPRISES 21212
957 PHANTOM'S BAR AND GRILL 21213
976 POPEYES FAMOUS FRIED CHICKEN 21212
994 ROBBIE'S NEST 21213
1017 RUTLAND BAR 21213
1018 RYAN'S DAUGHTER 21212
1022 saigon remembered restaurant 21212
1053 SHIRLEY'S HONEY HOLE 21213
1120 STEEPLE CHASE II 21213
1122 SUBWAY 21213
1153 TAM-TAM 21212
1155 TASTE 21212
1159 TAYLORS EAST 21213
1186 THE EDGE BAR & LOUNGE 21213
1187 THE EDGE BAR & LOUNGE - KITCHEN AREA 21213
1198 THE HOLLOW BAR & GRILL 21212
1209 THE NEW BUCKETT'S LOUNGE 21213
1232 THREE ACE'S 21213
1246 TORAIN'S HIDE-A-WAY 21213
1259 TSUNAMI BALTIMORE 21213
1287 VITO'S PIZZA 21212
1298 WENDY'S OLD FASHIONED HAMBURGERS #96 21212
1304 WHITTEN'S (4502-04) 21213
1312 wozi lounge 21212
1319 YETI RESTAURANT & CARRYOUT 21212
1320 YORK CLUB TAVERN 21212
1323 ZEN WEST ROADSIDE CANTINA 21212
1325 ZINK'S CAF\u0090 21213
 neighborhood councilDistrict policeDistrict
29 Downtown 11 CENTRAL
39 Broadway East 12 EASTERN
92 Chinquapin Park-Belvedere 4 NORTHERN
111 South Clifton Park 12 EASTERN
187 Rosebank 4 NORTHERN
220 Chinquapin Park-Belvedere 4 NORTHERN
266 Darley Park 14 NORTHEASTERN
276 Orangeville Industrial Area 13 EASTERN
289 Orangeville Industrial Area 13 EASTERN
291 Broadway East 12 EASTERN
362 Broadway East 13 EASTERN
373 Homeland 4 NORTHERN
383 Broadway East 13 EASTERN
417 Mid-Govans 4 NORTHERN
475 Chinquapin Park-Belvedere 4 NORTHERN
545 Broadway East 12 EASTERN
604 Mid-Govans 4 NORTHERN
616 Chinquapin Park-Belvedere 4 NORTHERN
620 Middle East 13 EASTERN
626 Belair-Edison 13 NORTHEASTERN
678 Chinquapin Park-Belvedere 4 NORTHERN
711 Homeland 4 NORTHERN
763 Oliver 12 EASTERN
777 Little Italy 1 SOUTHEASTERN
779 Broadway East 12 EASTERN
845 South Clifton Park 12 EASTERN
852 Radnor-Winston 4 NORTHERN
873 Wilson Park 4 NORTHERN
895 Biddle Street 13 EASTERN
919 Lake Walker 4 NORTHERN
940 Cedarcroft 4 NORTHERN
949 Rosebank 4 NORTHERN
957 Belair-Edison 3 NORTHEASTERN
976 Winston-Govans 4 NORTHERN
994 Broadway East 12 EASTERN
1017 Broadway East 12 EASTERN
1018 Chinquapin Park-Belvedere 4 NORTHERN
1022 Mid-Govans 4 NORTHERN
1053 Broadway East 13 EASTERN
1120 Biddle Street 13 EASTERN
1122 Oliver 12 EASTERN
1153 Mid-Govans 4 NORTHERN
1155 Mid-Govans 4 NORTHERN
1159 Berea 13 EASTERN
1186 Broadway East 12 EASTERN
1187 Broadway East 12 EASTERN
1198 Rosebank 4 NORTHERN
1209 Broadway East 13 EASTERN
1232 Belair-Edison 3 NORTHEASTERN
1246 Broadway East 12 EASTERN
1259 Little Italy 1 SOUTHEASTERN
1287 Cedarcroft 4 NORTHERN
1298 Homeland 4 NORTHERN
1304 Claremont-Freedom 13 NORTHEASTERN
1312 Guilford 4 NORTHERN
1319 Rosebank 4 NORTHERN
1320 Homeland 4 NORTHERN
1323 Rosebank 4 NORTHERN
1325 Belair-Edison 13 NORTHEASTERN
 Location.1
29 206 REDWOOD ST\nBaltimore, MD\n
39 1801 NORTH AVE\nBaltimore, MD\n
92 529 BELVEDERE AVE\nBaltimore, MD\n
111 1932 BELAIR RD\nBaltimore, MD\n
187 438 BELVEDERE AVE\nBaltimore, MD\n
220 529 BELVEDERE AVE\nBaltimore, MD\n
266 2701 ST LO DR\nBaltimore, MD\n
276 4217 ERDMAN AVE\nBaltimore, MD\n
289 4217 ERDMAN AVE\nBaltimore, MD\n
291 2101 NORTH AVE\nBaltimore, MD\n
362 2300 LAFAYETTE AVE\nBaltimore, MD\n
373 5422 YORK RD\nBaltimore, MD\n
383 1203 COLLINGTON AVE\nBaltimore, MD\n
417 5723 YORK RD\nBaltimore, MD\n
475 527 BELVEDERE AVE\nBaltimore, MD\n
545 2135 NORTH AVE\nBaltimore, MD\n
604 5847 YORK RD\nBaltimore, MD\n
616 529 BELVEDERE AVE\nBaltimore, MD\n
620 2201 CHASE ST\nBaltimore, MD\n
626 3349 BELAIR RD\nBaltimore, MD\n
678 529 BELVEDERE AVE\nBaltimore, MD\n
711 201 HOMELAND AVE\nBaltimore, MD\n
763 1000 HOFFMAN ST\nBaltimore, MD\n
777 1300 BANK STREET\nBaltimore, MD\n
779 1500 WASHINGTON ST\nBaltimore, MD\n
845 2001 BROADWAY\nBaltimore, MD\n
852 5100 YORK RD\nBaltimore, MD\n
873 4637 YORK RD\nBaltimore, MD\n
895 2301 BIDDLE ST\nBaltimore, MD\n
919 6307 1 2 YORK RD\nBaltimore, MD\n
940 6302 YORK RD\nBaltimore, MD\n
949 5928 YORK RD\nBaltimore, MD\n
957 3539 BELAIR RD\nBaltimore, MD\n
976 5002 YORK RD\nBaltimore, MD\n
994 2250 NORTH AVE\nBaltimore, MD\n
1017 1508 RUTLAND AVE\nBaltimore, MD\n
1018 600 BELVEDERE AVE\nBaltimore, MD\n
1022 5857 york rd\nBaltimore, MD\n
1053 2300 OLIVER ST\nBaltimore, MD\n
1120 2401 CHASE ST\nBaltimore, MD\n
1122 1400 NORTH AVE\nBaltimore, MD\n
1153 5722 YORK RD\nBaltimore, MD\n
1155 510 BELVEDERE AVE\nBaltimore, MD\n
1159 1201 POTOMAC ST\nBaltimore, MD\n
1186 2015 FEDERAL ST\nBaltimore, MD\n
1187 2015 FEDERAL ST\nBaltimore, MD\n
1198 5921 YORK RD\nBaltimore, MD\n
1209 1432 CHESTER ST\nBaltimore, MD\n
1232 3534 belair RD\nBaltimore, MD\n
1246 1701 ELLSWORTH ST\nBaltimore, MD\n
1259 1300 BANK ST\nBaltimore, MD\n
1287 6304 YORK RD\nBaltimore, MD\n
1298 5615 YORK RD\nBaltimore, MD\n
1304 4502 ERDMAN AVE\nBaltimore, MD\n
1312 4515 YORK RD\nBaltimore, MD\n
1319 5926 YORK RD\nBaltimore, MD\n
1320 5407 YORK RD\nBaltimore, MD\n
1323 5916 YORK RD\nBaltimore, MD\n
1325 3300 LAWNVIEW AVE\nBaltimore, MD\n

> data("UCBAdmissions")
> DF = as.data.frame(UCBAdmissions)
> summary(DF)
 Admit Gender Dept Freq 
 Admitted:12 Male :12 A:4 Min. : 8.0 
 Rejected:12 Female:12 B:4 1st Qu.: 80.0 
 C:4 Median :170.0 
 D:4 Mean :188.6 
 E:4 3rd Qu.:302.5 
 F:4 Max. :512.0 

> xt <- xtabs(Freq ~ Gender + Admit,data=DF)  ##Cross Tabs 
> xt
 Admit
Gender Admitted Rejected    ##Cross tabs are "Gender" and "Admit"
 Male 1198 1493
 Female 557 1278        ##table contents is "Freq"

> warpbreaks$replicate <- rep(1:9, len = 54)

> crosstab = xtabs(breaks ~.,data=warpbreaks) ##. = all variables
, , replicate = 1  ##So you get a long list for "replicate", "tension", and "wool"

 tension
wool L M H
 A 26 18 36
 B 27 42 20

, , replicate = 2

 tension
wool L M H
 A 30 21 21
 B 14 26 21

, , replicate = 3

 tension
wool L M H
 A 54 29 24
 B 29 19 24

, , replicate = 4

 tension
wool L M H
 A 25 17 18
 B 19 16 17

, , replicate = 5

 tension
wool L M H
 A 70 12 10
 B 29 39 13

, , replicate = 6

 tension
wool L M H
 A 52 18 43
 B 31 28 15

, , replicate = 7

 tension
wool L M H
 A 51 35 28
 B 41 21 15

, , replicate = 8

 tension
wool L M H
 A 26 30 15
 B 20 39 16

, , replicate = 9

 tension
wool L M H
 A 67 36 26
 B 44 29 28

> ftable(crosstab)      ##Turn it into a Flat Table!
             replicate 1  2  3  4  5  6  7  8  9
wool tension 
A    L                26 30 54 25 70 52 51 26 67
     M                18 21 29 17 12 18 35 30 36
     H                36 21 24 18 10 43 28 15 26
B    L                27 14 29 19 29 31 41 20 44
     M                42 26 19 16 39 28 21 39 29
     H                20 21 24 17 13 15 15 16 28

> fakeData = rnorm(1e5)
> object.size(fakeData)   ##What's the size in bytes?
800040 bytes

> print(object.size(fakeData),units="Mb")  ##What's the size in Mb?
0.8 Mb

Wolfie

Wolfie lives moment to moment seeking to make life more wonderful for all. She is passionate about people, animals, nature, and health, and she helps others express their creativity and live in harmony.