r how to subset without retaining all data info from original set? -
this question has answer here:
- drop factor levels in subsetted data frame 12 answers
i trying subset data.
here's link sample data play around with: https://drive.google.com/file/d/0bwibultiwxevofdrae81nm9qc2s/view?usp=sharing
so in data set, last column has name "type", has 2 values: "normal." , "back." , let's subsetting based on "type" column:
test.data = read.csv(file = paste0(dd, '/data_example.csv')) test.subdata1 = subset(test.data, test.data$type == 'normal.') test.subdata2 = test.data[test.data$type == 'normal.',] here, i'm subsetting using 2 common methods:
by using
subset()by directly filtering in
[]
supposedly, new subsetted data should contain data has type ``"normal." (there's period behind word) , indeed, when view subset data table, there's "normal." ones present.
however, thing is, "back." class info retained in subsetted data, shown in following output:
str(test.subdata1$type) # factor w/ 2 levels "back.","normal.": 2 2 2 2 2 2 2 2 2 2 ... str(test.subdata2$type) # factor w/ 2 levels "back.","normal.": 2 2 2 2 2 2 2 2 2 2 ... so not matter subsetting method use, complete information original data set retained in subset data set.
my question is: how rid of info original data set not want retain in subset data set?
meaning, how can see 1 factor level in subset data , not 2 factor levels?
# need? test.subdata1$type = as.factor(as.integer(test.subdata1$type)) # or maybe test.subdata1$type = factor(test.subdata1$type)
Comments
Post a Comment