Hi I am new to R. I am having this problem t1 <- read.csv("myfile.csv") t2 <- data.frame(t1) which have 10 row and 10 columns t2[1,1] does not give the first element but it gives the levels, how can I fix it. I will be thankful to community. -- View this message in context: http://r.789695.n4.nabble.com/Accessing-single-element-of-data-frame-tp2302770p2302770.html Sent from the R help mailing list archive at Nabble.com.
The solution to (most R problems) is as follows: 1.if asking for help include reproducible examples including parts of your data otherwise we can just guess what kind of data you have. 2. In general, refer to the help pages of the functions you use ( help(read.csv),help(data.frame) ) ( i have to confess that a similar problem puzzled me for quite a while, so here comes suggestion 3: 3. As a start, have a look what kind of data you have: class(t1) class(t2) class(t2[2,]) I would guess that t2 is a factor and not a vector and that the problem lies in read.csv converting whatever data you have to factors. See ?read.csv and the stringsAsFactors argument of that call. Adjusting its values might fix your problem. If not, go back to advice 1 ;-) HTH Jannis vacas schrieb:> Hi I am new to R. > I am having this problem > t1 <- read.csv("myfile.csv") > t2 <- data.frame(t1) > which have 10 row and 10 columns > t2[1,1] does not give the first element but it gives the levels, how can I > fix it. > > I will be thankful to community. >
On Jul 26, 2010, at 3:22 PM, vacas wrote:> > Hi I am new to R. > I am having this problem > t1 <- read.csv("myfile.csv") > t2 <- data.frame(t1) > which have 10 row and 10 columns > t2[1,1] does not give the first element but it gives the levels, how > can I > fix it.It gives you both. Factors are generally printed with the value and then the vector of possible values. By the way the use of data.frame would be redundant. The object returned by read.csv would already be a dataframe. ?read.csv ?data.frame -- David Winsemius, MD Heritage Laboratories West Hartford, CT
On Jul 26, 2010, at 3:22 PM, vacas wrote:> > Hi I am new to R. > I am having this problem > t1 <- read.csv("myfile.csv") > t2 <- data.frame(t1) > which have 10 row and 10 columns > t2[1,1] does not give the first element but it gives the levels, how > can I > fix it.It gives you both. Factors are generally printed with the value and then the vector of possible values. By the way the use of data.frame would be redundant. The object returned by read.csv would already be a dataframe. ?read.csv ?data.frame -- David Winsemius, MD Heritage Laboratories West Hartford, CT
I am so thankful to Jannis and David for answering. Surely, it did work and I am thankful to you all. -- View this message in context: http://r.789695.n4.nabble.com/Accessing-single-element-of-data-frame-tp2302770p2307563.html Sent from the R help mailing list archive at Nabble.com.