I have encountered a more fundamental problem in my data set. I''m using read.csv, and all the data are imported as character. How do I do a string comparison in a line like this: M10[ !sapply(1:10, function(x)666 %in% M10[x,]), ] Alternately, how do I change the class type on a column in a data frame from character to numeric? Thank you very much. Payam [[alternative HTML version deleted]]
Never mind the query regarding setting attributes. I just found the relevant section in the manual. The only remaining question is regarding doing string comparisons in sapply argument below. Thank you. Payam I have encountered a more fundamental problem in my data set. I''m using read.csv, and all the data are imported as character. How do I do a string comparison in a line like this: M10[ !sapply(1:10, function(x)666 %in% M10[x,]), ] Alternately, how do I change the class type on a column in a data frame from character to numeric? Thank you very much. Payam [[alternative HTML version deleted]]
Hi there, It may works: df$myvar<-as.numeric(as.character(df$myvar)) bests milton brazil=toronto On Thu, Jun 11, 2009 at 7:37 PM, Payam Minoofar <payam.minoofar@meissner.com> wrote:> I have encountered a more fundamental problem in my data set. I'm using > read.csv, and all the data are imported as character. How do I do a string > comparison in a line like this: > > M10[ !sapply(1:10, function(x)666 %in% M10[x,]), ] > > Alternately, how do I change the class type on a column in a data frame > from character to numeric? > > Thank you very much. > > Payam > > [[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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]