Alfredo Lozano
Alfredo Lozano

Reputation: 290

R create a variable from row values

I'm working with data from an "income/expense per home" poll done by the mexican government in which every tenement can contain more than one home.

There is a unique 6 digit folium number per tenement and a two digit indentifier for a single home in the tenement (00 means its the main home, 01 means its the second one and on); so it looks like this:

Folium.ten   Folium.hom
091001       00
091001       01
091002       00
091003       00
091003       01
091003       02

*note that the number of homes can vary

What I wish to do is to create a new variable upon this two to be able to identify each home easier, my thought looks like this (I'm open for different solutions):

Folium.ten   Folium.hom   Folium.id
091001       00           09100100
091001       01           09100102
091002       00           09100200
091003       00           09100300
091003       01           09100301
091003       02           09100302

Thanks!

Upvotes: 0

Views: 68

Answers (3)

sunny
sunny

Reputation: 3891

You can use

df$Folium.id <- paste0(df$Folium.ten, df$Folium.hom)

Upvotes: 1

akrun
akrun

Reputation: 886948

You can try

df$Folium.id <- do.call(paste0, df)
df
#  Folium.ten Folium.hom Folium.id
#1     091001         00  09100100
#2     091001         01  09100101
#3     091002         00  09100200
#4     091003         00  09100300
#5     091003         01  09100301
#6     091003         02  09100302

Upvotes: 2

jeremycg
jeremycg

Reputation: 24945

df$Folium.id <- paste0(dat$Folium.ten,dat$Folium.hom)

Upvotes: 1

Related Questions