Hi Daniel,

Thanks for the reply, that was the one missing piece!  I had been trying to
use the tapply() function, but was getting an error message about unequal
length until now.

I wrote:

VAL_mean_xpart <- tapply(X[ ,2], PARTF, mean)

and got the column 2 means by factors just as I had hoped.

One more question: how could I make an expression that would automatically
perform this operation for all columns 2 through ncol?  I tried:

VAL_mean_xpart <- tapply(X[ ,*2:n*], PARTF, mean)   and

VAL_mean_xpart <- tapply(X[ ,*2:ncol(X)*], PARTF, mean)

but obviously I was just unsure of how to specify "each column in the data
frame".  Thanks again for your help!

Best,
Logan



On Sat, Oct 15, 2011 at 2:22 PM, Daniel Malter [via R] <
ml-node+s789695n3908298...@n4.nabble.com> wrote:

> You access columns of a data.frame by column indices as in: X[ ,1], X[ ,2],
> etc. The index before the comma would stand for the row if you wanted to
> restrict those. The index after the comma captures the column.
>
> That said, you typically would not "extract" rows from the data frame but
> draw directly from the data frame for an analysis contingent on the factors
> in column 1. You may want to look at the tapply() function, in particular.
>
> HTH,
> Daniel
>
> jawbonemurphy wrote:
> Hi,
>
> I converted an Excel file into a .txt file "X.txt" with no header 
> (X.txt<http://r.789695.n4.nabble.com/file/n3908157/X.txt>)
> and imported it with:
>
> X <- read.table("/Users/johnlogandurland/Desktop/X.txt", header=FALSE).
>
> What I would like to do is to make the first column into a factors vector,
> and then analyze the rest of the columns in the data table using those
> factors.  The problem is, I haven't found a way to convert the rest of the
> columns into vectors with length = nrows so I can apply the factors vector
> to them.
>
> When I try:
>
> vect <- X[1]
>
> I get an object with class "data.frame" and length 1, and the "[[]]"
> command seems to turn the column into a "factor" vector, though with the
> right length.  This seems like it should be a really easy thing to do, but
> I've looked through R-intro and been unable to find a good answer.  Any
> ideas?
>
> Many Thanks,
> Logan
>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://r.789695.n4.nabble.com/Turning-Data-Frame-Columns-into-Vectors-tp3908157p3908298.html
>  To unsubscribe from Turning Data Frame Columns into Vectors, click 
> here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3908157&code=amR1cmxhbmRzdGVyQGdtYWlsLmNvbXwzOTA4MTU3fDE4NTIyMTcxNzk=>.
>
>


--
View this message in context: 
http://r.789695.n4.nabble.com/Turning-Data-Frame-Columns-into-Vectors-tp3908157p3908393.html
Sent from the R help mailing list archive at Nabble.com.
        [[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.

Reply via email to