[R] R column assignment fails for lists

David Winsemius dwinsemius at comcast.net
Wed May 4 03:48:13 CEST 2016


> On May 3, 2016, at 4:13 PM, Yasir Suhail <yasir.suhail at gmail.com> 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$c, ",") returns and then perhaps re-consider trying to assign it to a single column.

> 
> 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]
>> a[,2] <- a[,2]
>> a[,3] <- a[,3]
> Warning message:
> In `[<-.data.frame`(`*tmp*`, , 3, value = list(c("a", "b"), c("c",  :
>  provided 2 variables to replace 1 variables
> 
> 	[[alternative HTML version deleted]]

And please reconsider also the format of your postings.

> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list