Useful R tricks Flashcards
To convert coded categorical data
filecall$columnname=
replace( fc$cn, fc$cn==categorycode, ‘varname’)
![](https://s3.amazonaws.com/brainscape-prod/system/cm/223/537/204/a_image_thumb.png?1509145316)
view all column data of a specific type
ColumnName$ColumnData
![](https://s3.amazonaws.com/brainscape-prod/system/cm/223/597/334/a_image_thumb.png?1509204090)
Create table of column data of specific variable type
table(ColumnName$ColumnData)
![](https://s3.amazonaws.com/brainscape-prod/system/cm/223/597/396/a_image_thumb.png?1509204068)
View the proportion of each data type in a column from table t
prop=prop.table(table name)
![](https://s3.amazonaws.com/brainscape-prod/system/cm/223/597/648/a_image_thumb.png?1509205570)
View the percent of each data type in a column of table t
percent=prop.table(table name)*100
![](https://s3.amazonaws.com/brainscape-prod/system/cm/223/597/781/a_image_thumb.png?1509205583)
Creating category names for pie charts
for pie(tablename, _____)
paste(c(“category1”,”cat2”,”cat3”), function for percent, “%”, sep=” “)
Combines data
![](https://s3.amazonaws.com/brainscape-prod/system/cm/223/597/792/a_image_thumb.png?1509205594)
Display graphic output in new window
add x11()
in the console or before the code
![](https://s3.amazonaws.com/brainscape-prod/system/cm/223/601/794/a_image_thumb.png?1509208584)
build a histogram
hist(columndata, parameters….)
![](https://s3.amazonaws.com/brainscape-prod/system/cm/223/601/910/a_image_thumb.png?1509208651)
histogram breaks function
hist(actor_age$Age,
breaks=10,
main=”“,….)
Changes the interval reported for data
The following command will show you the five-number summary and the mean value of the data
summary(actor_age$Age)
For the Mean:
mean(actor_age$Age)
For the Standard Deviation:
sd(actor_age$Age)
For the Variance:
var(actor_age$Age)
For the Median:
median(actor_age$Age)