Hi I have a data frame with 40,000 rows and 4 columns, one of which is "class". For each row, the "class" column can be one of 10 possible NUMERIC values. I wish to substitute these numeric values with words/characters. For example, I wish to substitute all occurences of "5467" in the column "class" with "alpha", "7867" with "gamma", etc. I looked up substitute, but did not find any relevant examples. Your input is greatly appreciated Thanks Lalitha ____________________________________________________________________________________ Never miss an email again!
Lalitha Viswanath wrote:> I have a data frame with 40,000 rows and 4 columns, > one of which is "class". > > For each row, the "class" column can be one of 10 possible NUMERIC > values. I wish to substitute these numeric values with > words/characters. For example, I wish to substitute all occurences > of "5467" in the column "class" with "alpha", "7867" with "gamma", > etc. I looked up substitute, but did not find any relevant > examples.The substitute() function has nothing whatever to do with your problem. The following may give you the right idea: > xxx <- sample(1:10,100,TRUE) > yyy <- letters[1:10][match(xxx,1:10)] cheers, Rolf Turner rolf at math.unb.ca
Hi lalitha, You can try this way. I think it should solve the problem. Data looks like this Y X1 1 1 2 1 3 0 4 1 5 1 6 1 anal.data <- read.table("file.txt", header=T)\ attach(anal.data) ## objective is to change the value 1 in column X1 to Gamma anal.data$X1 <- replace(anal.data$X1,anal.data$X1==1,"Gamma") anal.data this should replace all the "1"'s with Gamma. Hope this helps. Sincerely "However bad life may seem, there is always something you can do and succeed at. While there is life, there is hope." Stephen Hawking Anup Menon Nandialath ********************************************************* http://www.soundclick.com/bands/7/tailgunner_music.htm * ********************************************************* --------------------------------- It's here! Your new message! Get new email alerts with the free Yahoo! Toolbar. [[alternative HTML version deleted]]
Reasonably Related Threads
- Packages in R for least median squares regression and computing outliers (thompson tau technique etc.)
- table of means/medians across bins used for a histogram
- Query about using table
- Package for phylogenetic tree analyses
- Query about getting averages across a certain parameter in a table