SEARCH
You are in browse mode. You must login to use MEMORY

   Log in to start


From course:

IST 387 Fall 2020

» Start this Course
(Practice similar questions for free)
Question:

What is the basic syntax in R?

Author: Zhasmina Yanislavova Tacheva



Answer:

<- is the "assignment operator," used to declare new variables and assign values to them (technically, = can be used for assignment too) # in the beginning of a line of code is used to mark that line as a comment (aka "comment it out") name_of_function() - you can identify functions in R by the parentheses following them. For example, mean(name_of_df_column) is applying the mean() function to all numbers in a dataframe column, i.e. the function arguments, or what you want to apply the function to, go inside the parentheses; in this case, the mean() function returns a single value, the average of the numbers in the dataframe column new_df <- df[df$likelihood_to_recommend == 8, ] - this is a typical way of "subsetting" from a dataframe called df. In this case, new_df is a subset of df containing all of df's columns (because there is nothing following the comma inside the square brackets - remember, the comma is used to separate the rows we want - before the comma, from the columns - after the comma), but only certain rows - the rows for which the likelihood_to_recommend column in df has a value of exactly 8. You can modify this condition - e.g. you can change == to >, in which case only rows with likelihood_to_recommend values greater than 8 will be included in the new dataframe. $ - this operator is used for "getting inside" a dataframe. E.g. df$likelihood_to_recommend means we want to access the likelihood_to_recommend column in the df dataframe. df$text means we want to access another column in that dataframe - the column called "text."


0 / 5  (0 ratings)

1 answer(s) in total