View source: R/findColumn.byname.r
findColumn.byname | R Documentation |
Sometimes in data manipulation we face the task of locating the position of a specific variable within a dataframe. The function finds the position in which a column name is within an object.
findColumn.byname(data = data, col.name = col.name)
data |
is a dataframe |
col.name |
is a string specifying the name of the variable |
Although the function finds the position of a specific variable, can also be used for more than one variable.
This function returns the number of a specific column-name.
It can be used for a vector of specified column-names as well.
Christian Salas-Eljatib
Salas-Eljatib, C. 2021. Análisis de datos con el programa estadístico R: una introducción aplicada. Ediciones Universidad Mayor, Santiago, Chile. 170 p. https://eljatib.com/rlibro
df <- data.frame(varX=1:5, varY=letters[1:5], varZ=rep("a",5),
varK=rep("b",5))
df
#using the function
findColumn.byname(df, c("varY","varZ"))
findColumn.byname(df, "varK")
#Creating an example vector
vector <- letters
vector
findColumn.byname(vector, c("h","z"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.