User Tools

Site Tools


r:data_transformations

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_transformations [2016/10/12 08:59] – [Applying a Function to Groups of Rows] hkimscilr:data_transformations [2019/09/19 18:23] (current) – [Splitting a Vector into Groups] hkimscil
Line 6: Line 6:
 Warning message: Warning message:
 패키지 ‘MASS’는 R 버전 3.2.5에서 작성되었습니다  패키지 ‘MASS’는 R 버전 3.2.5에서 작성되었습니다 
-> split(Cars93$MPG.city, Cars93$Origin)+> split(Cars93$MPG.city, Cars93$Origin) # Origin별로 MPG.city를 나눠라
 $USA $USA
  [1] 22 19 16 19 16 16 25 25 19 21 18 15  [1] 22 19 16 19 16 16 25 25 19 21 18 15
Line 39: Line 39:
 [1] 23.86667 [1] 23.86667
  
 +# or
 +> sapply(g, mean)
 +     USA  non-USA 
 +20.95833 23.86667 
 +# or retain list format
 +> lapply(g, mean)
 +$USA
 +[1] 20.95833
 +
 +$`non-USA`
 +[1] 23.86667
 +
 +
 </code> </code>
 ====== Applying a Function to Each List Element ====== ====== Applying a Function to Each List Element ======
Line 180: Line 193:
  
 <code>suburbs <- read.csv("suburbs.csv", head=T, sep=" ") <code>suburbs <- read.csv("suburbs.csv", head=T, sep=" ")
 +suburbs <- read.csv("http://commres.net/wiki/_export/code/r/data_transformations?codeblock=15", head=T, sep=" ")
 </code> </code>
  
Line 246: Line 260:
               (Other)   :21                                                                  (Other)   :21                                                   
 </code> </code>
-              + 
 +<code>tapply(suburbs$pop, suburbs$state, summary) 
 +</code>               
 + 
 +<code>by(suburbs$pop, suburbs$state, summary) 
 +</code>              
  
r/data_transformations.1476232171.txt.gz · Last modified: 2016/10/12 08:59 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki