Re: [R] Stuck with levels while reassigning dataframe colnames?

2012-02-02 Thread jjap
Thanks for the advice,
  df-read.table(infile, sep=, skip = 1,  header=TRUE)
is indeed much cleaner from the outset (and was my usual way to it).
I was unaware that 
  readLines(infile, n=1) 
could get me the first line without reading the whole file again.
But I do need to get my head around these levels...

---Jean Plamondon

--
View this message in context: 
http://r.789695.n4.nabble.com/Stuck-with-levels-while-reassigning-dataframe-colnames-tp4350435p4351528.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


[R] Stuck with levels while reassigning dataframe colnames?

2012-02-01 Thread jjap
Dear users,
I am importing a csv file whose first row is a single value that I need to
capture in a variable.
  infile-file.choose()
  in-read.csv( infile, header=FALSE)
  single.value-as.character(in[1,1])  # fine

Now I need to take rows 3 and on as the data
  df-in[3:dim(in)[1],]

But row 2 contains what I want as header of df.
  colnames(df)-in[2,]
This gets a series of numbers (characters) 2 5 3 11 instead of: 
   CatA Time etc. 
I suspect this has something to do with levels, but I cannot seem to find a
way to get the proper names.
Any help or hint is appreciated.


--
View this message in context: 
http://r.789695.n4.nabble.com/Stuck-with-levels-while-reassigning-dataframe-colnames-tp4350435p4350435.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


[R] ddply - how to transform df column in place

2011-08-23 Thread jjap
Dear R-users,

I am trying to get the plyr syntax right, without much success.

Given:
d- data.frame(cbind(x=1,y=seq(20100801,20100830,1)))
names(d)-c(first, daterep)
d2-d

# I can convert the daterep column in place the classic way:
d$daterep-as.Date(strptime(d$daterep, format=%Y%m%d))

# How to do it the plyr way?
ddply(d2, c(daterep), function(df){as.Date(df, format=%Y%m%d)})
# returns: Error in as.Date.default(df, format = %Y%m%d) : 
#   do not know how to convert 'df' to class Date

Thanks for any hints,

---jean

--
View this message in context: 
http://r.789695.n4.nabble.com/ddply-how-to-transform-df-column-in-place-tp3764037p3764037.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


[R] lattice panel.abline use

2011-08-12 Thread jjap
Dear R-users,

I am unsuccessful in trying to add an horizontal line to all graphs in the
example below:

library(lattice)
val-runif(15)
x-rep(seq(1:5),3)
type-c(rep(a,5), rep(b,5), rep(c,5))

xyplot(val ~ x | type, panel.abline(h=.6))

Any hints are appreciated.
Best regards,

---Jean



--
View this message in context: 
http://r.789695.n4.nabble.com/lattice-panel-abline-use-tp3739693p3739693.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Plotting a quadratic line on top of an xy scatterplot

2011-04-11 Thread jjap
Hi,

Is it just me or it appears the temperature and probability should be
reversed? 

Anyhow it should help you to assign your model to a variable (as Joshua did
with his own suggestion)

yourmodel -lm(x[,2] ~ x[,1] + I(x[,1]^2)) # again, taking literally the way
you formulated it...

And you could then access the coefficients individually:

c - coef(yourmodel)[1] # for the intercept 
b - coef(yourmodel)[2] 
a - coef(yourmodel)[3] 

To build yourself a vector of predicted y-values based on a vector of
x-values (dat as per Joshua's post)
and pass them to the lines function to be plotted over your existing plot.

This is less convenient than using the predict but sometimes it helps to
do the arithmetic at a lower level.
HTH


--
View this message in context: 
http://r.789695.n4.nabble.com/Plotting-a-quadratic-line-on-top-of-an-xy-scatterplot-tp3443018p3443693.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


[R] Simple but elusive - expand back from counts

2011-03-29 Thread jjap
Dear R-users,

This should be simple but still eludes me:

Given the following
tmp-as.data.frame(matrix(c(44, 10, abc, 1, 44, 10, def, 1, 44, 12,
abc, 2), 3, 4, byrow=T))

I want to  expand the data to the following form:

  V1 V2  V3 V4
1 44 10 abc  1
2 44 10 def  1
3 44 12 abc  1
4 44 12 abc  1

The last row of the original df was duplicated the row by the number in the
4th column (which could be expendable being all ones)
I clumsily tried a few variants of a loop but I am not making any progress.
Any hints would be greatly appreciated.
for (i in 1:3){
  rbind(rep(tmp[i,], temp[i,4])
  }

--
View this message in context: 
http://r.789695.n4.nabble.com/Simple-but-elusive-expand-back-from-counts-tp3415727p3415727.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Simple but elusive - expand back from counts

2011-03-29 Thread jjap
Many thanks to all, the first 3 solutions worked nicely but I did not get
around to tweaking properly the others. It's really nice to get thing going
in a one liner or about... Again greatly appreciated. Cheers!

--
View this message in context: 
http://r.789695.n4.nabble.com/Simple-but-elusive-expand-back-from-counts-tp3415727p3416068.html
Sent from the R help mailing list archive at Nabble.com.

__
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.