D******n 发帖数: 2836 | 1 有一个dataframe叫data,里面有三列叫 id,x,y
怎么样比较快的算出每个id的cor(x,y) |
s*r 发帖数: 2757 | 2 tapply?
【在 D******n 的大作中提到】 : 有一个dataframe叫data,里面有三列叫 id,x,y : 怎么样比较快的算出每个id的cor(x,y)
|
s*****n 发帖数: 2174 | 3 sapply(split(data, data$id), function(t) cor(t$x, t$y))
【在 D******n 的大作中提到】 : 有一个dataframe叫data,里面有三列叫 id,x,y : 怎么样比较快的算出每个id的cor(x,y)
|
t**i 发帖数: 688 | 4 by(data, data$id, function(t) cor(t$x, t$y)) |
D******n 发帖数: 2836 | 5 this is good but the output is "by" format
【在 t**i 的大作中提到】 : by(data, data$id, function(t) cor(t$x, t$y))
|
D******n 发帖数: 2836 | 6 thanks, good to know split. now i understand the list data type and apply se
ries better..
【在 s*****n 的大作中提到】 : sapply(split(data, data$id), function(t) cor(t$x, t$y))
|
t**i 发帖数: 688 | 7 do.call("rbind", by(...))
【在 D******n 的大作中提到】 : this is good but the output is "by" format
|
s*****n 发帖数: 2174 | 8 Yes, actually lapply+split is a common way to do "for"-type loop, but in a
much more efficient way. Other "apply"s are just wrappers of lapply.
se
【在 D******n 的大作中提到】 : thanks, good to know split. now i understand the list data type and apply se : ries better..
|
m********n 发帖数: 11 | 9 想问一下songkun,DaShagen和其他熟悉R的xdjm,你们能不能推荐几本R教程?谢谢!
我个情况是,用过1年多R,会用各种apply;理解functional programming;C++/
Matlab系统学过,比较熟练;python/scheme也会一点,语法和模块不太熟悉;SAS会一
点,比较讨厌这种语言。以后做analysis打算都用R,想深入理解R和熟悉各种
functionality。 |
s*****n 发帖数: 2174 | 10 我觉得会用各种apply就至少算中级吧, 这种
情况下看书基本用处不大, 就得多用多实践了.
【在 m********n 的大作中提到】 : 想问一下songkun,DaShagen和其他熟悉R的xdjm,你们能不能推荐几本R教程?谢谢! : 我个情况是,用过1年多R,会用各种apply;理解functional programming;C++/ : Matlab系统学过,比较熟练;python/scheme也会一点,语法和模块不太熟悉;SAS会一 : 点,比较讨厌这种语言。以后做analysis打算都用R,想深入理解R和熟悉各种 : functionality。
|
D******n 发帖数: 2836 | 11 manipulating data in R?
hehe, i dont quite have time to finish it though.
【在 m********n 的大作中提到】 : 想问一下songkun,DaShagen和其他熟悉R的xdjm,你们能不能推荐几本R教程?谢谢! : 我个情况是,用过1年多R,会用各种apply;理解functional programming;C++/ : Matlab系统学过,比较熟练;python/scheme也会一点,语法和模块不太熟悉;SAS会一 : 点,比较讨厌这种语言。以后做analysis打算都用R,想深入理解R和熟悉各种 : functionality。
|
m********n 发帖数: 11 | 12 明白,谢谢!
【在 s*****n 的大作中提到】 : 我觉得会用各种apply就至少算中级吧, 这种 : 情况下看书基本用处不大, 就得多用多实践了.
|
m********n 发帖数: 11 | 13 Thanks! It seems that this book is good for me to understand some
fundamentals of R in depth.
【在 D******n 的大作中提到】 : manipulating data in R? : hehe, i dont quite have time to finish it though.
|