Dear All Sorry for this simple question, I could not solve it by spending days.
My data looks like this: # data set.seed(1234) clvar <- c( rep(1, 10), rep(2, 10), rep(3, 10), rep(4, 10)) # I have 100 level for this factor var; yvar <- rnorm(40, 10,6); var1 <- rnorm(40, 10,4); var2 <- rnorm(40, 10,4); var3 <- rnorm(40, 5, 2); var4 <- rnorm(40, 10, 3); var5 <- rnorm(40, 15, 8) # just example df <- data.frame(clvar, yvar, var1, var2, var3, var4, var5) # manual splitting df1 <- subset(df, clvar == 1) df2 <- subset(df, clvar == 2) df3<- subset(df, clvar == 3) df4<- subset(df, clvar == 4) df5<- subset(df, clvar == 5) # i tried to mechanize it * for(i in 1:5) { df[i] <- subset(df, clvar == i) } I know it should not work as df[i] is single variable, do it did. But I could not find away to output multiple dataframes from this loop. My limited R knowledge, did not help at all ! * # working on each of variable, just trying simple function a <- 3:8 out1 <- lapply(1:5, function(ind){ lm(df1$yvar ~ df1[, a[ind]]) }) p1 <- lapply(out1, function(m)summary(m)$coefficients[,4][2]) p1 <- do.call(rbind, p1) My ultimate objective is to apply this function to all the dataframes created (i.e. df1, df2, df3, df4, df5) and create five corresponding p-value vectors (p1, p2, p3, p4, p5). Then output would be a matrix of clvar and correponding p values clvar var1 var2 var3 var4 var5 1 2 3 4 Please help me ! Thanks NIL [[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.