O'Reilly logo

R Statistical Application Development by Example Beginner's Guide by Prabhanjan Narayanachar Tattar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – creating a data.frame object

Here, we create data.frame from vectors. New objects are then added to an existing data frame and some preliminary manipulations are demonstrated.

  1. Create a numeric and character vector of length 3 each with x <- c(2,3,4); y <- LETTERS[1:3].
  2. Create a new data frame with df1<-data.frame(x,y).
  3. Verify the variable names of the data frame, the classes of the components, and display the variables distinctly with variable.names(df1); sapply(df1, class); df1$x; df1$y.
  4. Add a new numeric vector to df1 with df1$z <- c(pi,sqrt(2), 2.71828) and verify the changes in df1 by entering df1 at the console.
  5. Nullify the x component of df1 and verify the change.
  6. Bring back the original x values with df1$x <- x.
  7. Add a fourth ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required