简体   繁体   English

R studio 无法识别我的变量? 任何想法为什么?

[英]R studio wont recognize my variables? any ideas why?

So I imported the file and saved it as Purity and its clearly imported.因此,我导入了该文件并将其另存为 Purity 并清楚地导入了它。 I tried t-test but it doesn't recognize my variables.我试过 t 检验,但它不能识别我的变量。 I tried using the names function to retrieve the variable names and its exactly what I'm entering, V1 and V2.我尝试使用 names 函数来检索变量名称及其正是我输入的 V1 和 V2。 I also tried with Lab-1 and Lab-2.我也尝试过 Lab-1 和 Lab-2。 I also tried just using dataset=Purity, all to no avail.我也试过只使用 dataset=Purity,但都无济于事。

I took a screenshot so as to show code and that data is in the studio, can anyone tell me why this is not working?我截取了屏幕截图以显示代码并且该数据在工作室中,谁能告诉我为什么这不起作用?

在此处输入图片说明

apologies if this is painfully obvious I was only introduced to R for stats last week and am still a beginner, also don't have much experience with programming in general.抱歉,如果这很明显,我上周才被介绍到 R 进行统计,而且我仍然是初学者,总体上也没有太多的编程经验。 I have looked at other similar problems but just cant see why mine aren't being recognised and others are.我看过其他类似的问题,但不明白为什么我的没有被识别而其他人被识别。

You've got 2 issues here:你在这里有两个问题:

1). 1)。 You don't show how you imported the dataset but you need to either remove the first row or (better) name the columns correctly.您没有展示如何导入数据集,但您需要删除第一行或(更好)正确命名列。 I'm assuming you imported the data with read.table() .我假设您使用read.table()导入了数据。 If so, then include the argument header = TRUE when you import the data.如果是这样,则在导入数据时包含参数header = TRUE

2). 2)。 You need to tell R where you want it to get Lab-1 and Lab-2 from.您需要告诉 R 您希望它从何处获取Lab-1Lab-2

with(Purity, t.test(Lab-1, Lab-2, paired = TRUE))

r is case sensitive. r 区分大小写。 It looks like your script is using a lowercase 'v" when its an upper case "V" in your variable names.看起来您的脚本在变量名称中使用大写字母“V”时使用小写字母“v”。

The problem is in the way you have named your variable.问题在于您命名变量的方式。 r doesn't recognise the hyphen (-) as a legitimate part of a variable name. r 无法将连字符 (-) 识别为变量名的合法部分。 Try using underscore (_) instead.尝试改用下划线 (_)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM