Re: [R] Replace values in a dataframe

2015-06-17 Thread Grams Robins via R-help
Try this:  dat=structure(list(Color = c("5", "<4","5", "<5", "5"), Unit = c("Hazen","Hazen","Hazen", "Hazen", "Hazen")), .Names = c("Color", "Unit"), row.names =c("1:2","1:3", "1:4", "1:5","1:6"), class = "data.frame") dat=as.data.frame(dat)dat$col2 <- rep(" ", nrow(dat))dat[dat$Color == "<4", ][

Re: [R] Replace values in a dataframe

2015-06-17 Thread Bert Gunter
Is the following what you want: (z is your data frame) > change <-c("2","2.5") > names(change) <- c("<4","<5") (note: this can be automated using regular expressions and will work for lots more values to change. Sarah's ifelse() solution is fine for the example, but becomes too cumbersome (as sh

Re: [R] Replace values in a dataframe

2015-06-17 Thread Sarah Goslee
Hi Shane, On Wed, Jun 17, 2015 at 1:31 PM, Shane Carey wrote: > Hey all, > > I have a dataframe that consists of: > > structure(list(Color = c("5", "<4","5", "<5", "5"), Unit = c("Hazen", > "Hazen", > "Hazen", "Hazen", "Hazen")), .Names = c("Color", "Unit"), row.names = > c("1:2", > "1:3", "1:4",

[R] Replace values in a dataframe

2015-06-17 Thread Shane Carey
Hey all, I have a dataframe that consists of: structure(list(Color = c("5", "<4","5", "<5", "5"), Unit = c("Hazen", "Hazen", "Hazen", "Hazen", "Hazen")), .Names = c("Color", "Unit"), row.names = c("1:2", "1:3", "1:4", "1:5","1:6"), class = "data.frame") I need to find the <4 and have a new colum