Readers,
I have entered a file into r:
,column1,column2
row1,0.1,0.2
row2,0.3,0.4
using the command:
dataframe<-read.table("/path/to/file.csv",header=T,row.names=1)
When I try the command:
dataframe[,2]
I receive the response:
NULL
I was expecting:
row1 0.2
row2 0.4
What is my error with the syntax please?
Yours,
r251
mandriva2009
Use read.csv or read.table(..., sep = ","). Also note that if you delete the first comma of the header (as in the second example below) you won't have to specify row.names since it can figure it out from the fact that there is one fewer column name than data fields.> Lines <- ",column1,column2+ row1,0.1,0.2 + row2,0.3,0.4"> > read.csv(textConnection(Lines), row.names = 1)column1 column2 row1 0.1 0.2 row2 0.3 0.4> > > Lines2 <- "column1,column2+ row1,0.1,0.2 + row2,0.3,0.4"> > read.csv(textConnection(Lines2))column1 column2 row1 0.1 0.2 row2 0.3 0.4 On Mon, May 31, 2010 at 7:23 AM, e-letter <inpost at gmail.com> wrote:> Readers, > > I have entered a file into r: > > ,column1,column2 > row1,0.1,0.2 > row2,0.3,0.4 > > using the command: > > dataframe<-read.table("/path/to/file.csv",header=T,row.names=1) > > When I try the command: > > dataframe[,2] > > I receive the response: > > NULL > > I was expecting: > > row1 0.2 > row2 0.4 > > What is my error with the syntax please? > > Yours, > > r251 > mandriva2009 > > ______________________________________________ > R-help at 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. >
Hi,
Let's create your data.frame:
> dataframe <- structure(list(column1 = c(0.1, 0.3), column2 = c(0.2,
0.4)), .Names = c("column1",
"column2"), row.names = c("row1", "row2"), class =
"data.frame")
> dataframe[,2]
[1] 0.2 0.4
> dataframe[,2, drop=FALSE]
column2
row1 0.2
row2 0.4
So I don't know what's wrong with your data.
Maybe, providing the output from str(dataframe) would help us to help you!
HTH,
Ivan
Le 5/31/2010 13:23, e-letter a ?crit :> Readers,
>
> I have entered a file into r:
>
> ,column1,column2
> row1,0.1,0.2
> row2,0.3,0.4
>
> using the command:
>
>
dataframe<-read.table("/path/to/file.csv",header=T,row.names=1)
>
> When I try the command:
>
> dataframe[,2]
>
> I receive the response:
>
> NULL
>
> I was expecting:
>
> row1 0.2
> row2 0.4
>
> What is my error with the syntax please?
>
> Yours,
>
> r251
> mandriva2009
>
> ______________________________________________
> R-help at 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.
>
>
--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. S?ugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de
**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php
Apparently Analagous Threads
- How Can I insert another column data into the CSV file when I use FasterCSV?
- Reading sections of data files based on pattern matching
- barchart() {Lattice} help.
- using a value in a column to "lookup" data in a certian column of a dataset?
- sum(row1==y) if row2=x