Re: [R] Apply function to one specific column / Alternative to for loop

2013-11-17 Thread Stageexp
Hi, Try: indx <- grep("Test",test_df[,1])  ##assuming that there is some pattern  res <- within(test_df[-indx,],titel <- rep(test_df$titel[indx], diff(c(indx,nrow(test_df)+1))-1)) ## If you need to change the class res[] <- lapply(res,function(x) if(any(grepl("[[:alpha:]]",x))) as.character(x) e

Re: [R] Apply function to one specific column / Alternative to for loop

2013-11-16 Thread arun
Hi, Try: indx <- grep("Test",test_df[,1])  ##assuming that there is some pattern  res <- within(test_df[-indx,],titel <- rep(test_df$titel[indx], diff(c(indx,nrow(test_df)+1))-1)) ## If you need to change the class res[] <- lapply(res,function(x) if(any(grepl("[[:alpha:]]",x))) as.character(x)

Re: [R] Apply function to one specific column / Alternative to for loop

2013-11-16 Thread umair durrani
This might be of some use : http://nsaunders.wordpress.com/2010/08/20/a-brief-introduction-to-apply-in-r/ Umair Durrani email: umairdurr...@outlook.com > Date: Sat, 16 Nov 2013 07:30:29 -0800 > From: ron...@gmx.net > To: r-help@r-project.org > Subject: [R] Apply function to

[R] Apply function to one specific column / Alternative to for loop

2013-11-16 Thread Stageexp
Hi guys, I am a total newbie to R, so I hope this isn't a totally dumb question. I have a dataframe with a title in one row and the corresponding values in the next rows. Let's take this example: test_df <- data.frame(cbind(titel = "", x = 4:5, y = 1:2)) test_df = rbind(cbind(titel="1.Test", x=""