First Query:
File Name is Test which is a data frame and vector is only one containing names like Stacy-A, Mark-B, Giselle-C. I want to split a name lets say Stacy-A and I have more than 50000+ rows. So I want one vector containing Stacy and one vector containing A i.e. characters after split. I have run a loop for this. Since loop returns lists and I have used this.
for(i in 1:nrow(TEST)){TEST[i,"Name"]<-strsplit(TEST[i,"Name"],"-")[[1]][1]
TEST[i,"Character"]<-strsplit(TEST[i,"Name"],"-")[[1]][2]}
It takes a lot of time.
Can someone let me know how to use sapply
or any apply function but I want in data frame and not lists or matrix.
Second Query:
Test is my database which I want values and I have also one file named as User from which I want to pull values.
I want to put a lookup like excel to pick values from another file. I have two conditions in my loop. I find matching values then only I pick it and if there are duplicates I pick only one. I used this loop. It takes 3 hours. I have dataframe and for 300000+ rows in my user file from where I want values.
for (i in 1:nrow(Test)){if(Test[i,"Item_Cd"] %in% User_item_no)
{item_cd_found<-Test[i,"Item_Cd"]Test[i,"Order.Status"]<-as.character(User[which(User$Item.No.==item_cd_found),"Name"])[1]}