Skip to content
Prev 360648 / 398506 Next

R column assignment fails for lists

Hi Yasil,
If you look at what happens to a[,3] after the "strsplit" it is easy:
[1] "a,b" "c,d"

Here a[,3] is two strings

a$c <- strsplit(a$c, ",")
[[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] to replace the existing two values. Now if
you don't try to fool R:
[[1]]
[1] "a" "b"

[[2]]
[1] "c" "d"

Jim
On Wed, May 4, 2016 at 9:13 AM, Yasir Suhail <yasir.suhail at gmail.com> wrote: