Reputation: 103
I have the following data frame in R:
region_loop | test_regions
------ | ------
field1 | POSTAL_DIST_AB
field2 | POSTAL_DIST_AL
field3 | POSTAL_DIST_B
and I want to turn each row into an individual R value which would appear beneath the data sets on the right hand side of the R interface. NB: the number of rows within my table can change every time the code is run. The values would be:
Value content of value
field1 "POSTAL_DIST_AB"
field2 "POSTAL_DIST_AL"
field3 "POSTAL_DIST_B"
Upvotes: 0
Views: 63
Reputation: 103
I've found a way to do it:
for (i in 1:nrow(df)){
name = paste("fields",i,sep="")
assign(name,df[i,1])
}
Upvotes: 0
Reputation: 173627
A much better way to do this than using assign
would be to create a named vector or list:
setNames(df$test_regions,df$region_loop)
Upvotes: 3