r how to subset without retaining all data info from original set? -


this question has answer here:

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:

  1. by using subset()

  2. 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

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -