

Dear Community,
i have read in a table with two column from a *txtFile. What i get is a dataframe wit two column.
After that i allocate this 2 column to x and y. Plotting this, i obtain a picture that looks like a bar plot (something like a grid).
Is that because x and y is in factorformatted? A conversion with "asnumeric" doesnt work. I get a vector with "NA".
Here is my code:
daten<read.table("C:/Users/Robert/Desktop/regen.txt", header=FALSE, colClasses=c("real","real"))
x<daten[,1]
y<daten[,2]
plot(x,y)
Greetings


Hi,
As there is not much information like str() or the data, it is difficult to comment.
But, try this (considering your x and y are factors):
x<c("1","4","7","9","10","15")
y<c("3","5","8","6","5","14")
dat1<data.frame(x,y)
str(dat1)
'data.frame': 6 obs. of 2 variables:
$ x: Factor w/ 6 levels "1","10","15",..: 1 4 5 6 2 3
$ y: Factor w/ 5 levels "14","3","5","6",..: 2 3 5 4 3 1
dat2<dat1
dat2$x<as.numeric(as.character(dat2$x) )
is.numeric(dat2$x)
#[1] TRUE
dat2$y<as.numeric(as.character(dat2$y))
is.numeric(dat2$y)
#[1] TRUE
#Now try plot
x1<dat2[,1]
y1<dat2[,2]
plot(x1,y1)
Hope this helps.
A.K.
 Original Message 
From: sappy < [hidden email]>
To: [hidden email]
Cc:
Sent: Sunday, July 29, 2012 11:18 AM
Subject: [R] Simple x,y Plot
Dear Community,
i have read in a table with two column from a *txtFile. What i get is a
dataframe wit two column.
After that i allocate this 2 column to x and y. Plotting this, i obtain a
picture that looks like a bar plot (something like a grid).
Is that because x and y is in factorformatted? A conversion with
"asnumeric" doesnt work. I get a vector with "NA".
Here is my code:
daten<read.table("C:/Users/Robert/Desktop/regen.txt", header=FALSE,
colClasses=c("real","real"))
x<daten[,1]
y<daten[,2]
plot(x,y)
Greetings

View this message in context: http://r.789695.n4.nabble.com/SimplexyPlottp4638262.htmlSent from the R help mailing list archive at Nabble.com.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On 29.07.2012 17:18, sappy wrote:
> Dear Community,
>
> i have read in a table with two column from a *txtFile. What i get is a
> dataframe wit two column.
> After that i allocate this 2 column to x and y. Plotting this, i obtain a
> picture that looks like a bar plot (something like a grid).
> Is that because x and y is in factorformatted? A conversion with
> "asnumeric" doesnt work. I get a vector with "NA".
>
> Here is my code:
>
> daten<read.table("C:/Users/Robert/Desktop/regen.txt", header=FALSE,
> colClasses=c("real","real"))
As you are german, I suppose you used the comma as decimal separator.
You need to specify that in read.table by dec="," or R won't be able to
parse your numbers.
daten<read.table("C:/Users/Robert/Desktop/regen.txt", header=FALSE,dec=",)
Viele Grüße,
Moritz

GnuPG Key: 0x7340821E
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On 20120729 08:18, sappy wrote:
> Dear Community,
>
> i have read in a table with two column from a *txtFile. What i get is a
> dataframe wit two column.
> After that i allocate this 2 column to x and y. Plotting this, i obtain a
> picture that looks like a bar plot (something like a grid).
> Is that because x and y is in factorformatted? A conversion with
> "asnumeric" doesnt work. I get a vector with "NA".
Why don't you run str(daten) on the data.frame to see what you
actually imported? It's a good idea to always run a str() after
reading data.
And I wouldn't use 'real' as a colClass (although it does have
an 'as' method); I don't see it mentioned on the help page for
read.table.
Peter Ehlers
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Hello,
Inline
Em 29072012 17:41, arun escreveu:
> Hi,
>
> As there is not much information like str() or the data, it is difficult to comment.
>
> But, try this (considering your x and y are factors):
>
> x<c("1","4","7","9","10","15")
> y<c("3","5","8","6","5","14")
> dat1<data.frame(x,y)
> str(dat1)
> 'data.frame': 6 obs. of 2 variables:
> $ x: Factor w/ 6 levels "1","10","15",..: 1 4 5 6 2 3
> $ y: Factor w/ 5 levels "14","3","5","6",..: 2 3 5 4 3 1
>
> dat2<dat1
> dat2$x<as.numeric(as.character(dat2$x) )
> is.numeric(dat2$x)
> #[1] TRUE
> dat2$y<as.numeric(as.character(dat2$y))
> is.numeric(dat2$y)
>
> #[1] TRUE
> #Now try plot
> x1<dat2[,1]
> y1<dat2[,2]
> plot(x1,y1)
# Or, using the data.frame directly,
plot(y ~ x, data=dat2)
Hope this helps,
Rui Barradas
> Hope this helps.
>
> A.K.
>
>  Original Message 
> From: sappy < [hidden email]>
> To: [hidden email]
> Cc:
> Sent: Sunday, July 29, 2012 11:18 AM
> Subject: [R] Simple x,y Plot
>
> Dear Community,
>
> i have read in a table with two column from a *txtFile. What i get is a
> dataframe wit two column.
> After that i allocate this 2 column to x and y. Plotting this, i obtain a
> picture that looks like a bar plot (something like a grid).
> Is that because x and y is in factorformatted? A conversion with
> "asnumeric" doesnt work. I get a vector with "NA".
>
> Here is my code:
>
> daten<read.table("C:/Users/Robert/Desktop/regen.txt", header=FALSE,
> colClasses=c("real","real"))
> x<daten[,1]
> y<daten[,2]
> plot(x,y)
>
> Greetings
>
>
>
> 
> View this message in context: http://r.789695.n4.nabble.com/SimplexyPlottp4638262.html> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

