Brand new user: Data will not appear in my summary or plot

Hi I am a very new Rstudio user, trying to use R to complete an assignment per the instructions of my class but we were given virtually no class support and my teacher is non-responsive. We were given this code, however, when I run the summary, I do not receive the same data that the instructor does ( a second column of data that says A:14 above B:46). I have attached a photo of what I get. It seems like I have to define what to do with the data but I don't know how. Any help would be much appreciated. Thank you!Screen Shot 2021-04-14 at 4.15.19 PM

prefsAB = read.csv("prefsAB.csv")
prefsAB$Subject = factor(prefsAB$Subject) # convert to nominal factor

Here is the entire environment in case it helps...

Hi Nicole!

I think that there are two solutions.

One is convert into a factor the variable Pref before plotting it.

prefsAB$Pref <- factor(prefsAB$Pref)

The second solution is write the argument stringsAsFactors = TRUE in the read.csv() function.

prefsAB <- read.csv("prefsAB.csv", stringsAsFactors = TRUE)

This is because in the versions equal or bigger than R 4.0.0, read.csv() and the others functions for import data don't coerce into factors the strings. Maybe your teacher made this exercise before these actualizations.

You're welcome.


Thank you! This worked! I'm taking an online class that references a MUCH older version of R so I suspect you are right and am now incredibly nervous for the other 900 lines of code... :crossed_fingers:
Thanks again!

1 Like

I am very happy that you have found it useful!

As I can remember this is one of the latest most important changes in R base, maybe with some luck this could be the only type of problem that you could find. Good luck! :four_leaf_clover:

If you find that your teacher create a data frame with the data.frame() function, maybe you will have the same problem, you can solve this writing the argument stringsAsFactors = TRUE inside the function data.frame().

You're welcome! We are here to help us in what we can. :+1:


1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.