This is day one on R for me, I am trying to figure out how to do simple computations. For example I have a data set with 200 observations. I am trying to compute the mean and variance in r for 1:25 (first 25 observations); 1:50 (first 50 obs) ; 1:100th observation etc. Here is the dataset: Id value 1 2.2338 2 3.13597 3 1.98685 4 4.35593 5 2.43963 6 4.20262 7 3.12131 8 4.79583 9 3.13937 10 3.47266 11 3.79954 12 4.32285 13 3.00058 14 1.26102 15 4.07329 16 3.42037 17 1.99195 18 5.4461 19 3.03448 2 2.63395 21 0.99851 22 4.59577 23 2.77719 24 4.82748 25 4.11373 26 2.38615 27 1.81247 28 0.920195 29 2.78129 30 3.10531 31 3.60793 32 1.66597 33 4.80673 34 4.80266 35 5.35791 36 2.44573 37 2.63854 38 4.13737 39 1.68496 40 3.86962 41 1.60028 42 4.35621 43 3.60847 44 2.38884 45 1.03786 46 5.48904 47 1.95086 48 2.75401 49 2.25081 50 3.46435 51 0.309484 52 2.49405 53 4.52522 54 1.17947 55 2.50136 56 1.74537 57 5.48072 58 1.81081 59 2.67793 60 4.40603 61 3.21767 62 2.68124 63 1.9723 64 1.25973 65 2.64177 66 3.28414 67 3.2394 68 4.07508 69 2.32812 70 3.42763 71 2.40944 72 2.43776 73 0.072419 74 6.29773 75 2.29704 76 6.07705 77 1.59146 78 4.74327 79 5.29088 80 4.17874 81 1.80639 82 3.70503 83 3.13294 84 5.44017 85 3.50002 86 2.1762 87 2.27356 88 4.45687 89 1.99272 90 3.74362 91 3.89474 92 0.93481 93 4.99464 94 1.02872 95 2.63587 96 3.85226 97 4.82513 98 1.1171 99 1.09368 100 3.91599 101 3.91832 102 1.81166 103 1.48144 104 5.24373 105 3.15134 106 3.03343 107 3.373 108 6.10409 109 4.84878 110 1.95195 111 2.25949 112 1.45546 113 3.60767 114 3.10228 115 3.22694 116 0.861855 117 3.93392 118 2.81212 119 1.62434 120 2.41149 121 4.42936 122 2.4765 123 0.979153 124 3.3482 125 1.20345 126 1.56576 127 5.1418 128 3.5585 129 3.21124 130 3.52901 131 2.38191 132 3.6129 133 3.56378 134 2.70181 135 0.355836 136 3.10734 137 6.22159 138 4.7172 139 2.88295 140 2.87566 141 2.01538 142 2.78835 143 2.26519 144 1.38217 145 2.63885 146 1.0584 147 1.93247 148 3.10316 149 2.24714 150 5.08326 151 2.21789 152 4.63046 153 3.90057 154 2.19171 155 5.46094 156 1.84918 157 1.04059 158 4.57513 159 5.06956 160 3.65212 161 1.14078 162 5.89406 163 2.86261 164 1.87261 165 4.47285 166 3.13892 167 1.59146 168 1.07166 169 2.82925 170 2.83742 171 5.13528 172 3.20376 173 1.56253 174 3.08726 175 3.52339 176 3.66837 177 2.70302 178 2.00471 179 3.6823 180 2.90728 181 2.39302 182 2.54367 183 3.98498 184 4.17124 185 1.99922 186 2.61908 187 2.24057 188 3.29836 189 2.59912 190 4.49458 191 1.44657 192 2.99004 193 5.15769 194 2.64342 195 1.81755 196 5.1977 197 4.10043 198 4.63281 199 3.20347 200 2.08211
foo is the data frame you provided mean(foo[1:25,2]) var(foo[1:25,2]) indexing key: foo[rows,cols] hth Stephen Sefick On Tue, Oct 20, 2009 at 11:04 AM, Sibusiso Moyo <smoyo at vt.edu> wrote:> This is day one on R for me, I am trying to figure out how to do simple > computations. For example I have a data set with 200 observations. I am > trying to compute the mean and variance in r for 1:25 (first 25 > observations); 1:50 (first 50 obs) ; 1:100th observation etc. Here ?is the > dataset: > > Id value > 1 2.2338 > 2 3.13597 > 3 1.98685 > 4 4.35593 > 5 2.43963 > 6 4.20262 > 7 3.12131 > 8 4.79583 > 9 3.13937 > 10 3.47266 > 11 3.79954 > 12 4.32285 > 13 3.00058 > 14 1.26102 > 15 4.07329 > 16 3.42037 > 17 1.99195 > 18 5.4461 > 19 3.03448 > 2 2.63395 > 21 0.99851 > 22 > 4.59577 > 23 > 2.77719 > 24 > 4.82748 > 25 > 4.11373 > 26 > 2.38615 > 27 > 1.81247 > 28 > 0.920195 > 29 > 2.78129 > 30 > 3.10531 > 31 > 3.60793 > 32 > 1.66597 > 33 > 4.80673 > 34 > 4.80266 > 35 > 5.35791 > 36 > 2.44573 > 37 > 2.63854 > 38 > 4.13737 > 39 > 1.68496 > 40 > 3.86962 > 41 > 1.60028 > 42 > 4.35621 > 43 > 3.60847 > 44 > 2.38884 > 45 > 1.03786 > 46 > 5.48904 > 47 > 1.95086 > 48 > 2.75401 > 49 > 2.25081 > 50 > 3.46435 > 51 > 0.309484 > 52 > 2.49405 > 53 > 4.52522 > 54 > 1.17947 > 55 > 2.50136 > 56 > 1.74537 > 57 > 5.48072 > 58 > 1.81081 > 59 > 2.67793 > 60 > 4.40603 > 61 > 3.21767 > 62 > 2.68124 > 63 > 1.9723 > 64 > 1.25973 > 65 > 2.64177 > 66 > 3.28414 > 67 > 3.2394 > 68 > 4.07508 > 69 > 2.32812 > 70 > 3.42763 > 71 > 2.40944 > 72 > 2.43776 > 73 > 0.072419 > 74 > 6.29773 > 75 > 2.29704 > 76 > 6.07705 > 77 > 1.59146 > 78 > 4.74327 > 79 > 5.29088 > 80 > 4.17874 > 81 > 1.80639 > 82 > 3.70503 > 83 > 3.13294 > 84 > 5.44017 > 85 > 3.50002 > 86 > 2.1762 > 87 > 2.27356 > 88 > 4.45687 > 89 > 1.99272 > 90 > 3.74362 > 91 > 3.89474 > 92 > 0.93481 > 93 > 4.99464 > 94 > 1.02872 > 95 > 2.63587 > 96 > 3.85226 > 97 > 4.82513 > 98 > 1.1171 > 99 > 1.09368 > 100 > 3.91599 > 101 > 3.91832 > 102 > 1.81166 > 103 > 1.48144 > 104 > 5.24373 > 105 > 3.15134 > 106 > 3.03343 > 107 > 3.373 > 108 > 6.10409 > 109 > 4.84878 > 110 > 1.95195 > 111 > 2.25949 > 112 > 1.45546 > 113 > 3.60767 > 114 > 3.10228 > 115 > 3.22694 > 116 > 0.861855 > 117 > 3.93392 > 118 > 2.81212 > 119 > 1.62434 > 120 > 2.41149 > 121 > 4.42936 > 122 > 2.4765 > 123 > 0.979153 > 124 > 3.3482 > 125 > 1.20345 > 126 > 1.56576 > 127 > 5.1418 > 128 > 3.5585 > 129 > 3.21124 > 130 > 3.52901 > 131 > 2.38191 > 132 > 3.6129 > 133 > 3.56378 > 134 > 2.70181 > 135 > 0.355836 > 136 > 3.10734 > 137 > 6.22159 > 138 > 4.7172 > 139 > 2.88295 > 140 > 2.87566 > 141 > 2.01538 > 142 > 2.78835 > 143 > 2.26519 > 144 > 1.38217 > 145 > 2.63885 > 146 > 1.0584 > 147 > 1.93247 > 148 > 3.10316 > 149 > 2.24714 > 150 > 5.08326 > 151 > 2.21789 > 152 > 4.63046 > 153 > 3.90057 > 154 > 2.19171 > 155 > 5.46094 > 156 > 1.84918 > 157 > 1.04059 > 158 > 4.57513 > 159 > 5.06956 > 160 > 3.65212 > 161 > 1.14078 > 162 > 5.89406 > 163 > 2.86261 > 164 > 1.87261 > 165 > 4.47285 > 166 > 3.13892 > 167 > 1.59146 > 168 > 1.07166 > 169 > 2.82925 > 170 > 2.83742 > 171 > 5.13528 > 172 > 3.20376 > 173 > 1.56253 > 174 > 3.08726 > 175 > 3.52339 > 176 > 3.66837 > 177 > 2.70302 > 178 > 2.00471 > 179 > 3.6823 > 180 > 2.90728 > 181 > 2.39302 > 182 > 2.54367 > 183 > 3.98498 > 184 > 4.17124 > 185 > 1.99922 > 186 > 2.61908 > 187 > 2.24057 > 188 > 3.29836 > 189 > 2.59912 > 190 > 4.49458 > 191 > 1.44657 > 192 > 2.99004 > 193 > 5.15769 > 194 > 2.64342 > 195 > 1.81755 > 196 > 5.1977 > 197 > 4.10043 > 198 > 4.63281 > 199 > 3.20347 > 200 > 2.08211 > > ______________________________________________ > 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. >-- Stephen Sefick Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
Type ?mean ?sd in the R prompt. For your specific goal, type mean(r[1:25]) in the prompt. Proceed analogously for sd Just download one of the very many beginner's manuals or introductory course materials that you get for free on the internet, and get Ricci's R-refcard. Daniel ------------------------- cuncta stricte discussurus ------------------------- -----Urspr?ngliche Nachricht----- Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im Auftrag von Sibusiso Moyo Gesendet: Tuesday, October 20, 2009 12:05 PM An: r-help at r-project.org Betreff: [R] descriptive statistics qn This is day one on R for me, I am trying to figure out how to do simple computations. For example I have a data set with 200 observations. I am trying to compute the mean and variance in r for 1:25 (first 25 observations); 1:50 (first 50 obs) ; 1:100th observation etc. Here is the dataset: Id value 1 2.2338 2 3.13597 3 1.98685 4 4.35593 5 2.43963 6 4.20262 7 3.12131 8 4.79583 9 3.13937 10 3.47266 11 3.79954 12 4.32285 13 3.00058 14 1.26102 15 4.07329 16 3.42037 17 1.99195 18 5.4461 19 3.03448 2 2.63395 21 0.99851 22 4.59577 23 2.77719 24 4.82748 25 4.11373 26 2.38615 27 1.81247 28 0.920195 29 2.78129 30 3.10531 31 3.60793 32 1.66597 33 4.80673 34 4.80266 35 5.35791 36 2.44573 37 2.63854 38 4.13737 39 1.68496 40 3.86962 41 1.60028 42 4.35621 43 3.60847 44 2.38884 45 1.03786 46 5.48904 47 1.95086 48 2.75401 49 2.25081 50 3.46435 51 0.309484 52 2.49405 53 4.52522 54 1.17947 55 2.50136 56 1.74537 57 5.48072 58 1.81081 59 2.67793 60 4.40603 61 3.21767 62 2.68124 63 1.9723 64 1.25973 65 2.64177 66 3.28414 67 3.2394 68 4.07508 69 2.32812 70 3.42763 71 2.40944 72 2.43776 73 0.072419 74 6.29773 75 2.29704 76 6.07705 77 1.59146 78 4.74327 79 5.29088 80 4.17874 81 1.80639 82 3.70503 83 3.13294 84 5.44017 85 3.50002 86 2.1762 87 2.27356 88 4.45687 89 1.99272 90 3.74362 91 3.89474 92 0.93481 93 4.99464 94 1.02872 95 2.63587 96 3.85226 97 4.82513 98 1.1171 99 1.09368 100 3.91599 101 3.91832 102 1.81166 103 1.48144 104 5.24373 105 3.15134 106 3.03343 107 3.373 108 6.10409 109 4.84878 110 1.95195 111 2.25949 112 1.45546 113 3.60767 114 3.10228 115 3.22694 116 0.861855 117 3.93392 118 2.81212 119 1.62434 120 2.41149 121 4.42936 122 2.4765 123 0.979153 124 3.3482 125 1.20345 126 1.56576 127 5.1418 128 3.5585 129 3.21124 130 3.52901 131 2.38191 132 3.6129 133 3.56378 134 2.70181 135 0.355836 136 3.10734 137 6.22159 138 4.7172 139 2.88295 140 2.87566 141 2.01538 142 2.78835 143 2.26519 144 1.38217 145 2.63885 146 1.0584 147 1.93247 148 3.10316 149 2.24714 150 5.08326 151 2.21789 152 4.63046 153 3.90057 154 2.19171 155 5.46094 156 1.84918 157 1.04059 158 4.57513 159 5.06956 160 3.65212 161 1.14078 162 5.89406 163 2.86261 164 1.87261 165 4.47285 166 3.13892 167 1.59146 168 1.07166 169 2.82925 170 2.83742 171 5.13528 172 3.20376 173 1.56253 174 3.08726 175 3.52339 176 3.66837 177 2.70302 178 2.00471 179 3.6823 180 2.90728 181 2.39302 182 2.54367 183 3.98498 184 4.17124 185 1.99922 186 2.61908 187 2.24057 188 3.29836 189 2.59912 190 4.49458 191 1.44657 192 2.99004 193 5.15769 194 2.64342 195 1.81755 196 5.1977 197 4.10043 198 4.63281 199 3.20347 200 2.08211 ______________________________________________ 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.