Learn R Programming

datana (version 1.0.6)

findColumn.byname: 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)

Value

This function returns the number of a specific column-name.

Arguments

data

is a dataframe

col.name

is a string specifying the name of the variable

Author

Christian Salas-Eljatib

Details

Although the function finds the position of a specific variable, can also be used for more than one variable.

References

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

Examples

Run this code

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"))

Run the code above in your browser using DataLab