Reputation: 1
I know how to do this in Python, but right now I need to use R. I have a large dataframe with 15m records and 65 variables. I have subset the data to smaller regions of interest and I want to use the subset name as a variable in later steps in my script. For example
x <- subset(largedata, Name=="Test").
How to I get the name x
as a variable, not as a data input?
Upvotes: 0
Views: 309
Reputation: 56149
Alternative approach, split your data on Name column, then you have a named list, try this example:
mySplitData <- split(iris, iris$Species)
mySplitData
# $setosa
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 1 5.1 3.5 1.4 0.2 setosa
# ...
# $versicolor
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 51 7.0 3.2 4.7 1.4 versicolor
# ...
# etc
# to access by name:
mySplitData$setosa
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 1 5.1 3.5 1.4 0.2 setosa
# ...
In your example it would be something like:
mySplitData <- split(largedata, largedata$Name)
Upvotes: 1