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
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
> 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.
> 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$
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]
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]
6 matches
Mail list logo