Notes for R‐studio - bcb420-2024/Krutika_Joshi GitHub Wiki

  1. When making a data frame, it is important to specify stringAsFactors to be false so that R doesn't covert incorrect info into strings and run without an error/warning.

Functions:

  1. grep
  • grep(column grep needs to be applied to, pattern = "[]")
  • grep(myIDs$name, pattern = "^[0-9]")
  • NOTE: the hat sign outside means starts with
  • hat sign inside the brackets means not
  1. is.na()
  • Checks to see if the values in the vector are na
  • true if it is na
  1. Creating a new row
  • dataframeName$newColName <- calculate the column
  1. strsplit
  • unlist(strsplit(stringToBeSplit, "splitbywhat"))
  • unlist(strsplit(seq,""))
  • can operate on lists and value which is why unlist is nessasary
  1. rbind
  • adds a data frame to an already existing data Frame
  • df <- rbind(df, writeTheAdditionalDataFrame)
  1. unique
  • returns the unique values in the column
  • unique(colName)
  1. gsub
  • varnameNew <- gsub("[^A-Za-z]", "", varname)
  • "[^A-Za-z] means what should be substituted
  • varname is which variable needs to be substituted
  • varnameNew is the name of the new variable where we are storing the substituted value

RegEx:

Taken from

Cleaning R-History:

  • Open terminal
  • rm .Rhistory