R Program Code List: 9. Mean, Median and STDEV of Variable
This document lists 18 common R program code functions for working with data. These include functions to get information about functions (?code), view the working directory (getwd()), set the working directory (setwd()), check the dimension of data (dim()), find the length of a variable (length()), view the structure of data (str()), open a data source (View()), get summary statistics (summary()), find the mean, median, and standard deviation (mean/sd/median()), view variable names (names()), get frequency tables (table()), check the number of rows (nrow()) and columns (ncol()), create and fill new variables (rep(), data$), add labels (data[]), fill in new values with equations (data$variable
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
40 views
R Program Code List: 9. Mean, Median and STDEV of Variable
This document lists 18 common R program code functions for working with data. These include functions to get information about functions (?code), view the working directory (getwd()), set the working directory (setwd()), check the dimension of data (dim()), find the length of a variable (length()), view the structure of data (str()), open a data source (View()), get summary statistics (summary()), find the mean, median, and standard deviation (mean/sd/median()), view variable names (names()), get frequency tables (table()), check the number of rows (nrow()) and columns (ncol()), create and fill new variables (rep(), data$), add labels (data[]), fill in new values with equations (data$variable
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1
R program code list
1. 2. 3. 4.
Find out the function of some program
: ?code (ex: ?dim) To know working directory : getwd() set up new working directory : setwd() dimension of data structure (number of column and row) : dim(data) dim(data[data$variable_name==1,]) : dimension of variable_name in data with value =1 5. Length of a variable or vector : length(data$variable_name) 6. Structure of data sheet (variable and its value?) : str(data) 7. Open data source : View(data) 8. Summary statistic of variable (continuous variable) : summary(data$variable_name) (ex: summary(data$mom_wt)) mean, median, max, min 9. Mean, median and STDEV of variable : mean/sd/median(data$variable_name) 10. List of all variables : names(data) 11. Value of the table and the number of each group (summary table of dichotomized variable) table(data$variable_name) 12. Number of row : nrow(data) 13. Number of column : ncol(data) 14. Create a new variable data$variable_name=rep(NA, nrow(data)) or data$variable_name=rep(NA, 1000) : rep=replication; nrow(data) number of row to fulfill with NA 15. Labeling new variable : data[data$variable_name==1,settings]=new_variable_name (ex: data[data$living==1,settings]=urban 16. To fill new value in a variable : data$variable1=equation (ex: data$variable1=data$variable2/(data$variable3/100)^2 17. Boxplot for continuous variable boxplot(data$mom_wt) boxplot(data$mom_wt~data$settings) boxplot(data$mom_wt~data$settings, col=c("red","blue")) boxplot(data$mom_wt~data$settings, col=c("red","blue"), ylab="Maternal weight (kg)") 18. Histogram for continuous variable hist(data$mom_wt) hist(data$mom_wt, breaks=50) hist(data$mom_wt, breaks=50, col="grey") hist(data$mom_wt, breaks=50, col="grey", main="Histogram of maternal weight", xlab="maternal weight (kg)")