How do I add new columns into a data frame?

Hi everyone.

I'm trying to generate a data set from the rnorm function, using the sample size, mean, and standard deviations I've been creating from a hypothetical data set.

I've been looking on the internet in attempt to do this and been working at it all day.

So far I have...

ss.entrepreneur<-rnorm(60, 2.59, 0.504) #self-sufficiency of entrepreneurs
ss.manager<-rnorm(60, 2.11, 0.488) #self-sufficiency of managers
sc.entrepreneur<-rnorm(60, 3.16, 0.604) #self-confidence of entrepreneurs
sc.manager<-rnorm(60, 3.02, 0.542) #self-confidence of managers
at.entrepreneur<-rnorm(60, 2.91, 0.483) #ambiguity tolerance of entrepreneurs
at.manager<-rnorm(60, 2.79, 0.609) #ambiguity tolerance of managers
c.entrepreneur<-rnorm(60, 3.11, 0.471) #creativity of entrepreneurs
c.manager<-rnorm(60, 3.01, 0.478) #creativity of managers
loc.entrepreneur<-rnorm(60, 2.98, 0.509) #locus of control of entrepreneurs
loc.manager<-rnorm(60, 2.73, 0.556) #locus of control of managers
rtp.entrepreneur<-rnorm(60, 3.06, 0.561) #risk-taking propensity of entrepreneurs
rtp.manager<-rnorm(60, 3.00, 0.552) #risk-taking propensity of managers

N = n.entrepreneur + n.manager

simulateddata <- data.frame(
subject = c(seq(1,N),seq(1,N)),
characteristic = c(rep("self-confidence", N), rep("locus of control", N)), #within-subjects variable
occupation = c(rep(c(rep("entrepreneur", n.entrepreneur), rep("manager", n.manager)),2)), #between-subjects variable
value = c(sc.entrepreneur, sc.manager, loc.entrepreneur, loc.manager


I haven't been able to figure out a way to add more than two variables in the characteristic column, and have them correspond to values in the value column.

When I add more than two, I keep getting errors such as:

Error in data.frame(subject = c(seq(1, N), seq(1, N)), characteristic = c(rep("self-confidence", :
arguments imply differing number of rows: 240, 360.

Can anybody point me in the right direction? Thank you, any help is greatly appreciated!!

You need to check the length of your vectors. This means there are some differences somewhere in the resulting rows of the data.frame you are creating.

You could also change the way you are doing things. Like, creating a table by categories you want, smaller table with same number of column, then row binding them.

Just to help, you could be interesting in this book to improve your data manipulation skills.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.