Indicator function in R

If i am able to understand you correctly then you want to make changes into entire data frame,assuming of which i can suggest you to use apply like below, where df is your data frame. You can also use if its for only one vector something like below: Hope this helps

Categories R

Efficiently sum across multiple columns in R

I have the following condensed data set: I would like to sum the columns Var1 and Var2, which I use: In reality my data set is much larger – I would like to sum from Var_1 to Var_n (n can be upto 20). There must be a more efficient way to do this than:

Categories R

Error: Invalid number of ‘breaks’ in R

You have some problems in your syntax. Note that you have converted gender to a factor variable with values of “1” and “2” instead of “M” and “F”. If you run your code line-by-line, I’ll guess that it should work up to your last set of histograms. Change those lines to: Also, notice that I changed && to &. Run d$negotiated … Read more

Categories R Tags

How do I combine two data-frames based on two columns?

See the documentation on ?merge, which states: This clearly implies that merge will merge data frames based on more than one column. From the final example given in the documentation: This example was meant to demonstrate the use of incomparables, but it illustrates merging using multiple columns as well. You can also specify separate columns … Read more

Categories R

run a for loop in parallel in R

Thanks for your feedback. I did look up parallel after I posted this question. Finally after a few tries, I got it running. I have added the code below in case it is useful to others Note – I must add a note that if the user allocates too many processes, then user may get … Read more

Categories R

Error in : target of assignment expands to non-language object

These errors occur when you try to assign a value to a variable that doesn’t exist, or that R can’t treat as a name. (A name is a variable type that holds a variable name.) To reproduce the errors, try: (Can you guess which of the three errors NULL <- 1 returns?) A little-known feature of R is that you can assign … Read more