Re: [R] Unexpected behaviour as.data.frame

2011-05-16 Thread Jan van der Laan
Santosh, Ivan, This is also what I was looking for. Thanks. Looking at the source of dataFrame.default is seems that it uses the same approach as I did: first create a list then a data.frame from that list. I think I'll stick with the code I already had as I don't want another dependency (mult

Re: [R] Unexpected behaviour as.data.frame

2011-05-16 Thread Ivan Calandra
Forget this last email, I oversaw the implementation in the examples... Ivan Le 5/16/2011 11:35, Ivan Calandra a écrit : Actually, what would be even better would be an extra argument to specify the column names. I don't think it's very difficult to implement and it would make things even easi

Re: [R] Unexpected behaviour as.data.frame

2011-05-16 Thread Ivan Calandra
Actually, what would be even better would be an extra argument to specify the column names. I don't think it's very difficult to implement and it would make things even easier. Ivan Le 5/16/2011 11:25, Ivan Calandra a écrit : Thanks Santosh! The more I learn about R.utils, the more I think tha

Re: [R] Unexpected behaviour as.data.frame

2011-05-16 Thread Ivan Calandra
Thanks Santosh! The more I learn about R.utils, the more I think that many of its functions should be included in the base distribution. Ivan Le 5/16/2011 10:42, Santosh Srinivas a écrit : Hi Ivan, Take a look dataFrame in R.utils ... is that what you want? from the help file: Examples d

Re: [R] Unexpected behaviour as.data.frame

2011-05-16 Thread Santosh Srinivas
Hi Ivan, Take a look dataFrame in R.utils ... is that what you want? from the help file: Examples df <- dataFrame(colClasses=c(a="integer", b="double"), nrow=10) df[,1] <- sample(1:nrow(df)) df[,2] <- rnorm(nrow(df)) print(df) Thanks, Santosh On Mon, May 16, 2011 at 1:42 PM, Ivan Calan

Re: [R] Unexpected behaviour as.data.frame

2011-05-16 Thread Ivan Calandra
I feel like I'm always asking this type of questions, but is it possible to add a base function that allows creating an empty data.frame, as matrix() does? What I mean would be something like: create.data.frame(number_of_columns, mode_of_columns). I think it would make things easier than creati

Re: [R] Unexpected behaviour as.data.frame

2011-05-15 Thread Bert Gunter
Inline below. On Sun, May 15, 2011 at 11:11 AM, Jan van der Laan wrote: > Thanks. I also noticed myself minutes after sending my message to the list. > My 'please ignore my question it was just a stupid typo' message was sent > with the wrong account and is now awaiting moderation. > > However, m

Re: [R] Unexpected behaviour as.data.frame

2011-05-15 Thread Jan van der Laan
Thanks. I also noticed myself minutes after sending my message to the list. My 'please ignore my question it was just a stupid typo' message was sent with the wrong account and is now awaiting moderation. However, my other question still stands: what is the preferred/fastest/simplest way to cr

Re: [R] Unexpected behaviour as.data.frame

2011-05-15 Thread Bert Gunter
In your post, you're missing the final "s" on the stringsAsFactors argument in the d1 assignment. When I typed it correctly, it works as expected. -- Bert On Sun, May 15, 2011 at 4:25 AM, Jan van der Laan wrote: > I use the following code to create two data.frames d1 and d2 from a list: > types

[R] Unexpected behaviour as.data.frame

2011-05-15 Thread Jan van der Laan
I use the following code to create two data.frames d1 and d2 from a list: types <- c("integer", "character", "double") nlines <- 10 d1 <- as.data.frame(lapply(types, do.call, list(nlines)), stringsAsFactor=FALSE) l2 <- lapply(types, do.call, list(nlines)) d2 <- as.data.frame(l2, s

Re: [R] Unexpected behaviour as.data.frame

2011-05-15 Thread Jan van der Laan
Forget I asked. There was a typo in my example (stringsAsFactor instead of stringAsFactors) which explained the difference. My apologies. My second question however still stands: How does on create a data.frame with given column types and given dimensions? Thanks. Regards, Jan Quoting J