Hi, I am trying to calculate Principal Component Scores per id per year using the psych package. The following lines provide the scores per obeservation
pca = data.frame(read.table(textConnection(" id year A B C D 1001 1972 64 56 14 23 1003 1972 60 55 62 111 1005 1972 57 51 10 47 1007 1972 59 49 7 10 1009 1972 65 50 9 32 1011 1972 52 58 3 5 1013 1972 63 52 9 27 1001 1973 65 56 14 25 1003 1973 61 55 62 7 1005 1973 58 51 10 47 1007 1973 60 49 7 19 1009 1973 66 50 9 32 1011 1973 53 58 3 5 1013 1973 64 52 9 28 1001 1974 66 56 14 23 1003 1974 62 55 62 11 1005 1974 59 51 10 46 1007 1974 61 49 7 10 1009 1974 67 50 9 38 1011 1974 54 58 3 5 1013 1974 65 52 9 24 1001 1975 67 56 1 23 1003 1975 63 55 6 1 1005 1975 60 51 1 47 1007 1975 62 49 7 10 1009 1975 68 50 9 32 1011 1975 55 58 3 5 1013 1975 66 52 9 27"),head=TRUE)) library(psych) pcascores<-principal(pca[,-2], nfactors=1, score=TRUE) However, the scores should be based on the observations per year rather than the full set of observations. The final output should be a data frame with 7 rows (one for each id) and 4 columns (one for each year) filled with the Principal Component Scores per id per year. Any ideas on how to do this? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Find-Principal-Component-Score-per-year-tp3396132p3396132.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.