Notes for R‐studio - bcb420-2024/Krutika_Joshi GitHub Wiki
- 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:
- 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
- is.na()
- Checks to see if the values in the vector are na
- true if it is na
- Creating a new row
- dataframeName$newColName <- calculate the column
- strsplit
- unlist(strsplit(stringToBeSplit, "splitbywhat"))
- unlist(strsplit(seq,""))
- can operate on lists and value which is why unlist is nessasary
- rbind
- adds a data frame to an already existing data Frame
- df <- rbind(df, writeTheAdditionalDataFrame)
- unique
- returns the unique values in the column
- unique(colName)
- 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:
Cleaning R-History:
- Open terminal
- rm .Rhistory