Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过read.clipboard将数据从excel导入R_R_Excel - Fatal编程技术网

通过read.clipboard将数据从excel导入R

通过read.clipboard将数据从excel导入R,r,excel,R,Excel,我试图简化一个流程,通过该流程,我从excel工作表中选择并复制两列,然后将它们导入R,在R中进一步对它们进行子集划分。这是我的问题: excel数据在同一列中有多组数据。例如:第1列是[V,1,2,3,4,V,1,2,3,4],第2列是[A,2,4,6,10,A,3,6,9,12],其中V和A是列标题。我尝试复制两个相关列,然后在R中运行以下代码: testing<-read.clipboard(header=TRUE, sep=" ") testinga<-testing[1:

我试图简化一个流程,通过该流程,我从excel工作表中选择并复制两列,然后将它们导入R,在R中进一步对它们进行子集划分。这是我的问题:

excel数据在同一列中有多组数据。例如:第1列是[V,1,2,3,4,V,1,2,3,4],第2列是[A,2,4,6,10,A,3,6,9,12],其中V和A是列标题。我尝试复制两个相关列,然后在R中运行以下代码:

testing<-read.clipboard(header=TRUE, sep="  ")
testinga<-testing[1:4,]
结果图按第一个数字对我的数据点排序,即10标绘为1

如果我只是复制第一个数据集并使用read.clipboard导入它,这就不是问题

这是怎么回事,我该怎么处理

编辑:
你的问题是,如果bigdata.frame的列中有数字以外的内容,比如更多的列名,那么这些列就会被转换为因子而不是数字。您只需要将其转换回数值

testinga <- testing[1:4, ]
testinga <- sapply(testinga, FUN = function(x){as.numeric(as.character(x))})

然后你就可以很好地绘图了。

你能在你的问题中发布数据测试,这样我们就可以看到数据的样子吗?数据测试:structurelistV=structurec1L,2L,3L,5L,1L,2L,3L,4L,1L,Label=c1,2,3,4,V,class=factor,A=structurec3L,5L,6L,7L,2L,Label=c10,12,2,3,4,6,9,A,class=factor,.Names=cV,A,class=data.frame,row.Names=cNA,-9LIf如果我只复制第一个数据集,我会得到:dputtestingb:structurelistV=1:4,A=c2L,4L,6L,10L,.Names=cV,A,class=data.frame,row.Names=cNA,-4LThanks-然而,当我尝试这个时,我遇到了以下错误:错误:ggplot2不知道如何处理类矩阵的数据有什么方法可以解决这个问题吗?as.data.frametestinga
# from dput()
testing <- structure(list(V = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L), .Label = c("1", "2", "3", "4", "V"), class = "factor"), A = structure(c(3L, 5L, 6L, 1L, 8L, 4L, 6L, 7L, 2L), .Label = c("10", "12", "2", "3", "4", "6", "9", "A"), class = "factor")), .Names = c("V", "A"), class = "data.frame", row.names = c(NA, -9L))
testinga <- testing[1:4, ]
testinga <- sapply(testinga, FUN = function(x){as.numeric(as.character(x))})