An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080927/c6f56303/attachment.pl>
Using "by" to create individual variance-covariance matrices
2 messages · Josh B, Uwe Ligges
1 day later
Let me repeat an important topic from the the posting guide: it would be helpful for us to see a toy example, i.e. code to generate data for x. Best wishes, Uwe Ligges
Josh B wrote:
Hello R list subscribers,
I am trying to use the "by" command to create line-specific variance covariance matrices (where "x" is the original data matrix):
by(x, x$line, function(d) {
d.clean <- d[,-1]})
write.table(d.clean$line[1,1], sep = ",", file = "covariances.csv", col.names = FALSE, row.names = FALSE, append = TRUE)
write.table("", sep = ",", file = "covariances.csv", col.names = FALSE, row.names = FALSE, append = TRUE)
x.cov <- cov(d.clean, y= NULL, use= "complete.obs", method= c("pearson"))
})
When I run this code, I get an error:
by(x, x$line, function(d) {
+ d.clean <- d[,-1]})
Error in names(IND) <- deparse(substitute(INDICES))[1] :
'names' attribute [1] must be the same length as the vector [0]
Any suggestions on how to improve my code? Thanks in advance.
Sincerely, Josh
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list 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.