R Inserting a Dataframe/List into a Dataframe Element -


i'd insert dataframe dataframe element, such if called:df1[1,1] get:

[a b] [c d] 

i thought possible in r perhaps mistaken. in project of mine, working 50x50 matrix, i'd each element contain column of data containing numbers , labeled rows.

trying df1[1,1] <- df2 yields following warning

warning message: in [<-.data.frame(*tmp*, i, j, value = list(djn.10 = c(0, 3, : replacement element 1 has 144 rows replace 1 rows

and calling df1[1,1] yields 0 . i've tried inserting data in various ways, as.vector() , as.list() no success.

best,

perhaps matrix work you, so:

x <- matrix(list(), nrow=2, ncol=3) print(x) #     [,1] [,2] [,3] #[1,] null null null #[2,] null null null x[[1,1]] <- data.frame(a=c("a","c"), b=c("b","d")) x[[1,2]] <- data.frame(c=2:3) x[[2,3]] <- data.frame(x=1, y=2:4) x[[2,1]] <- list(1,2,3,5) x[[1,3]] <- list("a","b","c","d") x[[2,2]] <- list(1:5) print(x) #     [,1]   [,2]   [,3]   #[1,] list,2 list,1 list,4 #[2,] list,4 list,1 list,2 x[[1,1]] #  b #1 b #2 c d  class(x) #[1] "matrix"  typeof(x) #[1] "list" 

see here details.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -