string,list pair in a row in data frame in R -


i have data frame follows:

date = "2000" values = c("a","b","d") df <- data.frame(date=date,values= values) df   date values 1 2000      2 2000      b 3 2000      d 

actually have thousands of values in values field. instead of printing separate rows want make data frame contains 1 row contains information.ie, :

1 2000    a,b,d 

is possible in r, map<string,arraylist(string)> in java?

it's not clear want, here's code aggregate started:

> df$values <- as.character(df$values) > # `list` of values > (da1 <- aggregate(values ~ date, df, i, simplify=false))   date  values 1 2000 a, b, d > str(da1) 'data.frame':   1 obs. of  2 variables:  $ date  : factor w/ 1 level "2000": 1  $ values:list of 1   ..$ 0:class 'asis'  chr [1:3] "a" "b" "d"  > # values collapsed 1 string > (da2 <- aggregate(values ~ date, df, paste, collapse = ", ", simplify=false))   date  values 1 2000 a, b, d > str(da2) 'data.frame':   1 obs. of  2 variables:  $ date  : factor w/ 1 level "2000": 1  $ values:list of 1   ..$ 0: chr "a, b, d" 

i've shown structure can see difference between 2 examples here.


if understand comment below correctly, might interested in this:

> date = "2000" > values = c("a", "b", "d") > (temp <- data.frame(date, values = i(list(values))))   date  values 1 2000 a, b, d > str(temp) 'data.frame':   1 obs. of  2 variables:  $ date  : factor w/ 1 level "2000": 1  $ values:list of 1   ..$ : chr  "a" "b" "d"   ..- attr(*, "class")= chr "asis" 

in other words, if want have list column item when creating data.frame must use i function.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -