If you have: Name Value A 2 A 3 A 4 B 5 B 6 B 7 In R how do you assign one value to the name: A:9 B:18 -- View this message in context: http://r.789695.n4.nabble.com/for-loop-help-tp2539621p2539621.html Sent from the R help mailing list archive at Nabble.com.
How do I create a hash table using R? -- View this message in context: http://r.789695.n4.nabble.com/for-loop-help-tp2539621p2539657.html Sent from the R help mailing list archive at Nabble.com.
Most likely. If you care to be more specific, we might be able to give you a more specific answer. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of lord12 Sent: Wednesday, 15 September 2010 6:30 AM To: r-help at r-project.org Subject: [R] for loop help If you have: Name Value A 2 A 3 A 4 B 5 B 6 B 7 In R how do you assign one value to the name: A:9 B:18 -- View this message in context: http://r.789695.n4.nabble.com/for-loop-help-tp2539621p2539621.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.
An envorniment is a hash table. There are several packages that you might care to look at, e.g. filehasn -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of lord12 Sent: Wednesday, 15 September 2010 7:06 AM To: r-help at r-project.org Subject: Re: [R] for loop help How do I create a hash table using R? -- View this message in context: http://r.789695.n4.nabble.com/for-loop-help-tp2539621p2539657.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.
Hello, So you want to sum Value by Name and assign to an object in your workspace called Name ? (it's best to say specifically what the desired output is when you post a question here). Assuming your data are in a matrix or data.frame called foo, you could use a for loop as follows... for (nm in unique(foo$Name)) assign(nm, sum(foo$Value[foo$Name == nm])) You might also want to study the help pages for the functions tapply, by, and aggregate. Michael On 15 September 2010 06:29, lord12 <gaut222 at yahoo.com> wrote:> > If you have: > Name ? Value > A ? ? ? ? ? 2 > A ? ? ? ? ? 3 > A ? ? ? ? ? 4 > B ? ? ? ? ? 5 > B ? ? ? ? ? 6 > B ? ? ? ? ? ?7 > > > In R how do you assign one value to the name: > > A:9 > B:18 > -- > View this message in context: http://r.789695.n4.nabble.com/for-loop-help-tp2539621p2539621.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >