(mydata <- as.factor(c("1","2","3", ">2", "5", ">2"))) str(mydata)
newdata <- as.character(mydata) newdata[newdata==">2"] <- 0 newdata <- as.numeric(newdata) str(newdata) We really need to keep Excel (and other spreadsheets) out of peoples hands. John Kane Kingston ON Canada > -----Original Message----- > From: noahsilver...@ucla.edu > Sent: Tue, 28 Feb 2012 13:27:13 -0800 > To: r-help@r-project.org > Subject: [R] Cleaning up messy Excel data > > Unfortunately, some data I need to work with was delivered in a rather > messy Excel file. I want to import into R and clean up some things so > that I can do my analysis. Pulling in a CSV from Excel is the easy part. > > My current challenge is dealing with some text mixed in the values. > i.e. 118 5.7 <2.0 3.7 > > Since this column in Excel has a "<2.0" value, then R reads the column as > a factor with levels. Ideally, I want to convert it a normal vector of > scalars and code code the "<2.0" as 0. > > Can anyone suggest an easy way to do this? > > Thanks! > > > -- > Noah Silverman > UCLA Department of Statistics > 8117 Math Sciences Building > Los Angeles, CA 90095 > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.