Re: [R] R column assignment fails for lists

2016-05-04 Thread Yasir Suhail
Dear Jim and David, Thank you very much for your reply. I guess my question is whether it is legal to store vectors in the elements of a data.frame. These are useful for storing things like neighbors of a graph vertex, orthologs of a gene etc. I have been using data frames of this sort and they ar

Re: [R] R column assignment fails for lists

2016-05-03 Thread Bert Gunter
This is actually a bit subtle -- you need to carefully read the Help pages to see what's happening. Here's the explanation to the best of my understanding (corrections happily accepted if I've got it wrong!). First, let's simplify: > z <- data.frame(a = 1:2, b = list(a = letters[1:2], b = letters

Re: [R] R column assignment fails for lists

2016-05-03 Thread David Winsemius
> On May 3, 2016, at 4:13 PM, Yasir Suhail wrote: > > Dear R developers and users, > > Consider the object : > >> a <- data.frame(a=c(1,2), b=c(2,3), c=c("a,b","c,d"), stringsAsFactors = F) >> a$c <- strsplit(a$c, ",") > > Re-assignment works fine for columns 1 and 2, but fails for column 3.

Re: [R] R column assignment fails for lists

2016-05-03 Thread David Winsemius
> On May 3, 2016, at 4:13 PM, Yasir Suhail wrote: > > Dear R developers and users, > > Consider the object : > >> a <- data.frame(a=c(1,2), b=c(2,3), c=c("a,b","c,d"), stringsAsFactors = F) >> a$c <- strsplit(a$c, ",") You are the one who should "consider the object". Look at what strsplit(a$

Re: [R] R column assignment fails for lists

2016-05-03 Thread Jim Lemon
Hi Yasil, If you look at what happens to a[,3] after the "strsplit" it is easy: > a[,3] [1] "a,b" "c,d" Here a[,3] is two strings a$c <- strsplit(a$c, ",") > a[,3] [[1]] [1] "a" "b" [[2]] [1] "c" "d" Now a[,3] is a two element list. What R probably did was to take the first component of a[,3]

[R] R column assignment fails for lists

2016-05-03 Thread Yasir Suhail
Dear R developers and users, Consider the object : > a <- data.frame(a=c(1,2), b=c(2,3), c=c("a,b","c,d"), stringsAsFactors = F) > a$c <- strsplit(a$c, ",") Re-assignment works fine for columns 1 and 2, but fails for column 3. If a is a valid object, the assignment should work. > a[,1] <- a[,1]