I am a beginner in R.
After watching a number of tutorials on regression analysis (on youtube), I decided to make up my own data set and apply what I learnt to it. This is what I did!
I wanted to randomly create a list of salaries, ages and marital status.
Salaries
salary = sample(2000:3000, 250, replace = T)
Ages
ages = sample(20:50, 250, replace = T)
MaritalStatus
marSt = sample(c("MARRIED", "SINGLE"), 250, repeat = T)
Then, I combined the three sets of data with:
dataset = cbind(salary, ages, marSt)
Finally, I tried to run a regression on what I thought was my new data set with this command:
data.reg = lm(salary~ages+marSt, data = dataset)
… only for me to be told that there was an error and that the object “dataset” was actually NOT a dataset.
My question is two fold:
(i) Is it possible to create data sets from combinations of vectors?
(ii) If no, is there any way in R to create data sets without importing them from other sources?
Thank you very much and please I am a beginner and do not be too sophisticated in your response.
You probably want a
data.framenot amatrix(as returned bycbind),also, repeat is not an argument of
sample(), you probably meanreplace=TRUE. You would do well to read an introduction to R.