Ok, you're right - may I rephrase: How should I modify the assignment of result <- latentVariableNames so it produces the output without the first line? I thought result <- NULL should do the job, but it didn't because of the following names(result) assignment (which I understand, but not how I can workaround it).
Here's the output and code again: latentVariable Indiv Group 1 rPlanning rIterat rTDD 2 rPlanning 0.79 0.84 3 rIterat 0.79 0.83 4 rTDD 0.9 0.96 5 rStandup 0.83 0.82 6 rRetros 0.9 0.95 7 rAccess 0.91 0.92 8 rAccTest 0.87 0.9 ##### LV <- c("rPlanning", "rIterat", "rTDD", "rStandup", "rRetros", "rAccess", "rAccTest") ##### loopCronbach <- function(latentVariableNames, groupingVariable) { result <- latentVariableNames names(result) <- c("latentVariable", "Indiv", "Group") for (currentName in latentVariableNames) { print(currentName) print(result) tmp1 <- calculateIndividualCronbach(get(currentName)) tmp2 <- calculateGroupCronbach(get(currentName), groupingVariable) result <- rbind(result,data.frame(latentVariable=currentName, Indiv=tmp1,Group=tmp2)) } return(result) } On Thu, Feb 11, 2010 at 3:31 AM, jim holtman <jholt...@gmail.com> wrote: > It doing exactly what you asked it to do. You have the assignment: > > result <- latentVariableNames > > and then you print it out in the loop. What were you expecting? > > On Wed, Feb 10, 2010 at 9:06 PM, Chaehan So <chaehan...@gmail.com> wrote: > > Dear r-helpers, > > > > why do I get an output in the first iteration of the for-loop > > which contains the string values of the input vector, > > and how can I avoid that? > > > > Here's the output (only line 1 is wrong) > > > > latentVariable Indiv Group > > 1 rPlanning rIterat rTDD > > 2 rPlanning 0.79 0.84 > > 3 rIterat 0.79 0.83 > > 4 rTDD 0.9 0.96 > > 5 rStandup 0.83 0.82 > > 6 rRetros 0.9 0.95 > > 7 rAccess 0.91 0.92 > > 8 rAccTest 0.87 0.9 > > > > ##### > > LV <- c("rPlanning", "rIterat", "rTDD", "rStandup", "rRetros", "rAccess", > > "rAccTest") > > ##### > > loopCronbach <- function(latentVariableNames, groupingVariable) > > { > > result <- latentVariableNames > > names(result) <- c("latentVariable", "Indiv", "Group") > > for (currentName in latentVariableNames) > > { > > print(currentName) > > print(result) > > tmp1 <- calculateIndividualCronbach(get(currentName)) > > tmp2 <- calculateGroupCronbach(get(currentName), groupingVariable) > > result <- rbind(result,data.frame(latentVariable=currentName, > > Indiv=tmp1,Group=tmp2)) > > } > > return(result) > > } > > > > > > a <- loopCronbach(LV, u_proj) > > > > [[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 > > and provide commented, minimal, self-contained, reproducible code. > > > > > > -- > Jim Holtman > Cincinnati, OH > +1 513 646 9390 > > What is the problem that you are trying to solve? > -- Humboldt University Berlin, Germany Institute of Psychology Rudower Chaussee 18, Room 1221 12489 Berlin Germany Office: +49 30 2093 - 9337 Mobile: +49 171- 626 9373 [[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 and provide commented, minimal, self-contained, reproducible code.