I've recently found out using read.table i can insert a table into R from a .dat file. The problem i'm having is now that i've got R to read the package i want to use the data from each column. I've tried adding titles to each column using col.name, but it assigns a name to the entire table and wont recognize the name i gave the table later in programming. Is there something i'm doing wrong or am i missing an important step? I'd appreciate any help.
I've recently found out using read.table i can insert a table into R from a .dat file. The problem i'm having is now that i've got R to read the package i want to use the data from each column. I've tried adding titles to each column using col.name, but it assigns a name to the entire table and wont recognize the name i gave the table later in programming. Is there something i'm doing wrong or am i missing an important step? I'd appreciate any help.
I guess one of the reasons that you have not had a reply is that you have not followed the posting guide. If you give the list something to work with (a small reproducible example) You use the word package which in R is very precise, but which I think you are using to describe the file you are reading. This amkes it harder for us to understand what your problem is. if you type ?read.table and read the help you will find that the parameter col.names is a "a vector of optional names for the variables. The default is to use '"V"' followed by the column number." Typically this would look something like col.names = c("ColA","ColB", ..., "ColZ") That is one for each column in the matrix or data.frame. But I'm guessing. If I saw the code I might see something else that you've done to to see what you mean by "assigns a name to the entire table." Now's a good time to reread the posting guide, assuming that you have already done so. Tom> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Owen Buchner > Sent: Tuesday, 19 April 2005 10:16 AM > To: R-help at stat.math.ethz.ch > Subject: [R] using imported tables > > > I've recently found out using read.table i can insert a table > into R from a .dat > file. The problem i'm having is now that i've got R to read > the package i want > to use the data from each column. I've tried adding titles > to each column > using col.name, but it assigns a name to the entire table and > wont recognize > the name i gave the table later in programming. Is there > something i'm doing > wrong or am i missing an important step? I'd appreciate any help. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
While you may want to jump in at the deep end I would suggest that you need to take the time to fully digest some of the basics. This is one of them. There are a number of ways that can be used. You tell me you have a table, but I asume that you have a data.frame. I normally associate table with "an object of 'class' '"table"', an array of integer values." which is produced by the table command. in other words an array. However the read.table command returns a data.frame (see ?read.table, in particular Value: which tells you exactly what is returned by the function.) To help you understand what you really have use str(name.of.object) Data.frames and arrays can be subset by row or column using indexing that is df[1,] is row 1 of df df[,1] is column 1 of df df[1:2,] are the first two rows of df etc (but you do need to read about indexing arrays) If however you have a data.frame with named columns you can refer to them directly. So if column 1 is called Age then df$Age is the vector relating to that column. If you had a data.frame with named columns of income and persons which were both numeric than you could calculate gross income as df$GrossIncome <- df$income * df$persons. As a minimum* you need to read "An introduction to R." If you are using windows then in all probability it is one of the documents in your help system. There are also a number of excellent texts that take you through the basics of R. If you wish to gain proficiency you will find it easier to do this first. The list does not generally go out of its way to help people who have apparently not read the basic documentation. The list will not penalize you for not understanding so if you don't understand some component it helps when you indicate where you have gleaned your information from and what attempts you have made to solve your problem. Tom * The posting guide explains all of this much better than I do.> -----Original Message----- > From: Owen Buchner [mailto:OBUCHNER at DAL.CA] > Sent: Tuesday, 19 April 2005 7:51 PM > To: Mulholland, Tom > Subject: RE: [R] using imported tables > > > The table I uploaded has two columns and I've been able to > assign both a name. > The main problem is that i want to work with the data I had R > import using > read.table. I want to use one column at a time or have two > of the columns > multiplied together to yeild a new column but I'm not sure of > the commands I > can use to have R take one column from the table and use it > like a vector. >