Removing an entry in r -


in sas there capability remove observation through simple if statement. instance if wanted delete rows year = #. write:

if year == "#" delete;  

is there equivalent way in r? tried this:

 df<- df[!(df$year == "#"),] 

data set in r:

year        month #           june #           july  #           august 2015        august 

but when run df$year, still # factor level when thought filtered out?

you're doing right. still factor level, doesn't mean exists in vector df$year. can drop factor level if need droplevels or using factor again df$year <- factor(df$year)

if need convert factor numeric labels numeric vector, can use:

as.numeric( ## convert numeric expected   as.character( ## because factors numbers labels     your_factor      )   ) ) 

Comments

Popular posts from this blog

python - jinja2: TemplateSyntaxError: expected token ',', got 'string' -

Qt4: how to send QString inside a struct via QSharedMemory -

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -