findColumn.byname: Finds the position of a specific variable.

View source: R/findColumn.byname.r

findColumn.bynameR 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

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


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

datana documentation built on June 13, 2025, 1:11 a.m.