[BlindRUG] What's wrong with this data set? Why is R recognizing the Y variable but not the X variable?

Shawn Janzen sjanzen at umd.edu
Fri Jan 8 17:10:30 UTC 2021


Good morning Amy,

Jonathon was spot on about using str() to help check your data before you
start running any analysis.

To your question and a solution, I noticed you shared X and Y in a csv file
but the R mean command you gave expressed X and Y as separate objects and
not part of the same dataframe.  My code response here places X and Y in
the same dataframe since that is the default when importing a csv file.  I
call this dataframe d. My code also assumes you are in the same working
directory as your csv file.  Using str() I found that d$Y imported fine but
d$X did not exist. Instead variable X imported as ï..X or d$ï..X . I'm not
sure why this happened since the first row X and Y look fine when opened in
a basic text editor.  Not sure if it a row labels issue as Jonathon
mentioned since read.csv() has the header=TRUE option by default.  However,
in my code below I changed ï..X to X and things worked well from there.

d <- read.csv("CommuteandStressModified.csv")
str(d)
mean(Y) # does not work because Y is part of d
mean(d$Y) # = 4.55
mean(X)  # not found because it column name is ï..X
# fix column X label
colnames(d)[1] <- "X"
mean(d$X)   # = 39.85

Good luck!

Best,
Shawn
*________________________*
*Shawn Janzen* ● Instructor & PhD candidate  & CASCI Fellow & STC
Coordinator● (he/him/his)
University of Maryland ● College of Information Studies (iSchool)
4161 Fieldhouse Drive (Patuxent Building) ● Room 1109-K ● College Park, MD
20742

www.ischool.umd.edu ● sjanzen at umd.edu  ● casci.umd.edu  ● go.umd.edu/stc


On Thu, Jan 7, 2021 at 3:17 PM Godfrey, Jonathan via BlindRUG <
blindrug at nfbnet.org> wrote:

> Hello Amy,
>
> This is the sort of question that is much better sorted out in person
> rather than waiting for the email world to wake up.
>
> I suspect the problem is the way the data is imported. Get into the habit
> of checking what the variable names are and what data type they come in as
> using str()
> In this situation, my first guess is that the first column of the original
> file is being used as the row labels for the data instead of being one of
> the two variables of a dataset that should have no data labels.
>
> HTH
> Jonathan
>
>
>
> -----Original Message-----
> From: BlindRUG <blindrug-bounces at nfbnet.org> On Behalf Of Amy Albin via
> BlindRUG
> Sent: Friday, 8 January 2021 8:41 AM
> To: blindrug at nfbnet.org
> Cc: Amy Albin <amyralbin at gmail.com>
> Subject: [BlindRUG] What's wrong with this data set? Why is R recognizing
> the Y variable but not the X variable?
>
> Hello,
>
> I have 2 variables labeled "X and "Y". R is allowing me to do things like
> mean(Y) it says 4.55. But when I type
> mean(X)
> It says: error in mean(X): object X not found
>
> What's going on? Thank you.
> _______________________________________________
> BlindRUG mailing list
> BlindRUG at nfbnet.org
> http://nfbnet.org/mailman/listinfo/blindrug_nfbnet.org
> To unsubscribe, change your list options or get your account info for
> BlindRUG:
> http://nfbnet.org/mailman/options/blindrug_nfbnet.org/sjanzen%40umd.edu
> The list archive can be viewed at:
> http://www.nfbnet.org/pipermail/blindrug_nfbnet.org
> More information and useful links about using R as a blind person can be
> obtained at:
> http://R-Resources.massey.ac.nz
>
> Look for help using R commands by reading the accessible e-book "Let's Use
> R Now" compiled by Jonathan Godfrey at:
> http://R-Resources.massey.ac.nz/lurn/front.html
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nfbnet.org/pipermail/blindrug_nfbnet.org/attachments/20210108/8ccc5db5/attachment.html>


More information about the BlindRUG mailing list