User Tools

Site Tools


r:data_structures

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
r:data_structures [2019/09/19 18:03] – [Mode: Physical Type] hkimscilr:data_structures [2019/09/19 18:16] (current) – [Creating a Factor (Categorical Variable)] hkimscil
Line 135: Line 135:
  
 Grouping: This is a technique for labeling or tagging your data items according to their group. See the Introduction to Chapter 6. Grouping: This is a technique for labeling or tagging your data items according to their group. See the Introduction to Chapter 6.
 +
 +<code>> A <- c(1,2,2,3,3,4,4,4,4,2,1,2,3,3)
 +> A
 + [1] 1 2 2 3 3 4 4 4 4 2 1 2 3 3
 +> str(A)
 + num [1:14] 1 2 2 3 3 4 4 4 4 2 ...
 +> fA <- factor(A)
 +> fA
 + [1] 1 2 2 3 3 4 4 4 4 2 1 2 3 3
 +Levels: 1 2 3 4
 +> str(fA)
 + Factor w/ 4 levels "1","2","3","4": 1 2 2 3 3 4 4 4 4 2 ...
 +
 +</code>
  
 ===== Data Frames ===== ===== Data Frames =====
Line 227: Line 241:
 [1] 11 12 13 14 15 16 [1] 11 12 13 14 15 16
 </code> </code>
- 
-<WRAP box help>The above code is very useful. But, sometimes the recycling rule is very annoying. How would I avoid it? 
-</WRAP> 
  
 ====== Creating a Factor (Categorical Variable) ====== ====== Creating a Factor (Categorical Variable) ======
Line 252: Line 263:
  
 <code>> f <- factor(wday, c("Mon","Tue","Wed","Thu","Fri")) # c(...) part means "levels" not data  <code>> f <- factor(wday, c("Mon","Tue","Wed","Thu","Fri")) # c(...) part means "levels" not data 
-> f+> f  # note that there is no Fri in the below output.
  [1] Wed Thu Mon Wed Thu Thu Thu Tue Thu Tue  [1] Wed Thu Mon Wed Thu Thu Thu Tue Thu Tue
 Levels: Mon Tue Wed Thu Fri Levels: Mon Tue Wed Thu Fri
r/data_structures.1568883780.txt.gz · Last modified: 2019/09/19 18:03 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki