Tools/R Command A-Z

Command Function Example Result
str() Compactly Display the Structure of an Arbitrary R Object str(log) 'data.frame': 7 obs. of 2 variables:
pmin(), pmax() pmax and pmin take one or more vectors (or matrices) as arguments and return a single vector giving the ‘parallel’ maxima (or minima) of the vectors. Data_ori <- transform(Data_ori, days_Event = pmin(Data_ori$days_20111231OD1, Data_ori$days_OD2OD1, Data_ori$days_Endo1OD1, Data_ori$days_Ext1OD1, na.rm=TRUE)) get the min_day of each row (recoreds)
table() table uses the cross-classifying factors to build a contingency table of the counts at each combination of factor levels. table1 <-as.data.frame(table(Data_ori$days_Event))
hist() computes a histogram of the given data values hist(as.numeric(Data_ori$days_Event)) create a histogram
attach(), detach() The database is attached to the R search path. Detach Objects from the Search Path attach(Data_ori) database is searched by R when evaluating a variable, so objects in the database can be accessed by simply giving their names.
names() The Names of an Object names(Data_ori)
gsub() Pattern Matching and Replacement Data_ori$OD1stRDYes <- gsub("NULL",0, Data_ori$OD1stRDYes) replace NULL with '0'
is.na() ‘Not Available’ / Missing Values Data_ori [is.na(Data_ori )] <- 0 replace missing values with '0'
substr() Substrings of a Character Vector Data_ori$ToothPosition <- substr(Data_ori$IPID, 1, 2) extract first 2 characters
sub() Pattern Matching and Replacement Data_ori$DateOD1st <- sub('(.{4})(.{2})(.{2})', "\1-\2-\3", Data_ori$Date_OD_1st) convert a string to date
as.Date() Date Conversion Functions to and from Character Data_ori$days_20111231OD1 <- as.Date(as.character('2011-12-31'), format="%Y-%m-%d") - as.Date(as.character(Data_ori$DateOD1st), format="%Y-%m-%d") Count number of days since a specific date
as.character() Character Vectors Data_ori$days_20111231OD1 <- as.Date(as.character('2011-12-31'), format="%Y-%m-%d") - as.Date(as.character(Data_ori$DateOD1st), format="%Y-%m-%d") Count number of days since a specific date
transform() Transform an Object, for Example a Data Frame Data_ori <- transform(Data_ori, days_Event = pmin(Data_ori$days_20111231OD1, Data_ori$days_OD2OD1, Data_ori$days_Endo1OD1, Data_ori$days_Ext1OD1, na.rm=TRUE)) add a column to dataframe for Count number of survival days
select(){dplyr} survdata_run <- dplyr::select(Data_Analysis, 1,3:9,17) select variables
sample() Random Samples and Permutations Data1 <- Data1[sample(nrow(Data1), 50000), ] random select records

Reference:

results matching ""

    No results matching ""