Displaying 1 result from an estimated 1 matches for "dfxz".
Did you mean:
dfx
2010 Dec 27
3
Drop column from a data frame
...data frame. The code below attempts to drop a numeric column (which does not work but gives no error or warning) and a factor column (which does not work but gives an error).
I would appreciate someone telling me why my code does not work, and suggesting code that will work.
Thanks,
John
rm(dfxyz,dfxz,dfxy)
# create the data frame.
dfxyz <- data.frame(x=1:10,y=11:20,z=factor(c(rep(0,5),rep(1,5))))
dfxyz
names(dfxyz)
# try to drop y column
# does not work, does not produce error message
dfxz <- dfxyz[,-(dfxyz$y)]
dfxz
# try to drop z column
# does not work, produces error message:
# In...