findColumn.byname {datana} | R Documentation |
Finds the position of a specific variable.
Description
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.
Usage
findColumn.byname(data = data, col.name = col.name)
Arguments
data |
is a dataframe |
col.name |
is a string specifying the name of the variable |
Details
Although the function finds the position of a specific variable, can also be used for more than one variable.
Value
This function returns the number of a specific column-name.
Note
It can be used for a vector of specified column-names as well.
Author(s)
Christian Salas-Eljatib
Examples
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"))
[Package datana version 1.0.5 Index]