Reputation: 13
I have data frame named dcWCTOneSubTotal
which has column T1Description
having multiple values .
How to pass each value after storing this in a variable like descriptionName.
It returns null if i pass value as T1Description=='descriptionName'
to subset function.
It returns rows if i pass value as T1Description=="abc"
or T1Description=="xyz"
to subset function.
I want to call this
bar.Chart.D.F.1 <- subset(dcWCTOneSubTotal , T1Description=='descriptionName')
inside function so that I can have different subsets each time for different T1Description column.
Upvotes: 0
Views: 412
Reputation: 3914
As suggested in the comments - just omit the quotes:
dcWCTOneSubTotal <- data.frame(T1Description = c("a","b","c","a","c","b"),
T2Description = 1:6,
stringsAsFactors = FALSE)
dcWCTOneSubTotal
# T1Description T2Description
# 1 a 1
# 2 b 2
# 3 c 3
# 4 a 4
# 5 c 5
# 6 b 6
sub = "a"
subset(dcWCTOneSubTotal, T1Description==sub)
# T1Description T2Description
# 1 a 1
# 4 a 4
sub= "b"
subset(dcWCTOneSubTotal, T1Description==sub)
# T1Description T2Description
# 2 b 2
# 6 b 6
Upvotes: 1