有没有人知道如何解决这个R问题?[关闭]

dluptydi  于 2023-01-10  发布在  其他
关注(0)|答案(1)|浏览(161)

14小时前关门了。
Improve this question

我失去了我的头脑,因为读. csv功能。请帮助我,这是csv文件:

"y_ImageQuality,""x1_ISO"",""x2_FRatio"",""x3_TIME"",""x4_MP"",""x5_CROP"",""x6_FOCAL"",""x7_PixDensity"""
74.7330129340401,-1.40939052093635,0.166557921780591,-0.155572397629272,0.64607630162074,-1.62617736623778,0.952847460670872,1.41496913728781
67.5432023752774,-0.0716604389295692,-1.66595799177104,-0.198584466605318,0.00169312381011655,0.736982934003247,1.02940846395485,-0.320786877105595
105.729503496042,-0.55722469804096,-1.40446126037477,0.652277144766128,-1.48532207240364,-1.59005688833538,-0.99408209646237,0.0522503490583947
47.0330022432316,-0.291659752801807,0.624862855287145,-0.663044621619131,-1.30295341395846,0.363643108144905,-0.0668161684697757,-1.49598132852875
57.939665398463,1.33204133134493,-1.31404841665258,-0.392712122442248,-0.710038460934951,-1.43392127914641,1.22567316575666,0.257486744044466
76.4999411786952,0.98508946941744,-0.348814272309045,1.32581265741944,0.837713622863241,-1.59224092223241,-1.05322678694035,1.64741702493296
63.1344687342501,-0.855931610702315,-0.910433580058841,1.4845488048332,-0.766339875811571,0.529849868165681,-1.38642121741074,-1.06136570737907
65.882726444799,0.835401780790642,-0.356841513422753,1.19329686901978,-1.59942173613474,-0.847437209143806,0.976953937807624,-1.2266084883149
62.4800310482022,-0.238206785925336,-1.22762749772219,-0.171245096657208,-0.465864030185672,0.620914371224962,-0.43616583910485,-0.722868693092947
41.1685058188854,-0.17434554847549,0.877712381189007,-0.428186288427479,1.52662964522855,-0.183993065086296,-1.17477344591039,0.392515867145803
76.2089180933422,-0.834060130068257,-0.42270424659797,-0.657475278924916,-1.62991820990351,0.00927519181155145,-1.44588180006693,-1.72619565498181
62.5975862138583,-0.589543671726687,0.0705613400774838,-0.567094676999356,-0.826676251321994,0.521477302287334,-0.721255289630641,-1.17078897236914
51.0101695360249,0.409918811547778,-1.50467880904407,-1.62679452866723,0.154884354059842,0.64895194967966,1.69420001910776,-0.389967665556245
27.5906707229061,-0.242768988452696,1.11120214508511,0.737279703711012,0.779844913887356,0.829778682411543,0.0860063922608019,0.221897995505761
63.1603105612441,-1.06433181665174,-1.45692601436997,1.4767277418426,0.661199419767221,1.25114991965321,-1.22374845914276,0.704884284432009
71.9968658621166,-1.07979565578112,-0.320330442386048,0.776150109652145,0.866376822833387,-0.765765327399003,-0.101225251000816,0.370630511761045
41.3900263042833,0.178716667444446,1.47996611596102,0.872259572728319,-1.37482215707432,0.621174217925655,-1.27510582134897,-1.3641747620861
18.1920184529461,-1.44579483311352,1.20398988123555,-1.57220126280221,-0.275772587553154,1.58884311273213,-1.36463943793124,0.693449352304709
-4.26748319687819,1.30083945545896,1.45819904874199,-1.01333148868868,0.792372655722708,0.33384766338461,-1.31565388955572,-0.128164177458418
45.2678904202217,-1.43530114900012,0.967643242515257,-1.64446957432974,0.119566930389321,-0.389294636372357,-0.0991942412275686,-0.584932838154349
55.6321144557822,-0.995416094647759,-0.156343470579858,-0.177786586582984,0.916058804501126,0.807262502958334,0.0165576792819269,0.401686195074033
48.5701315919924,0.28886304250092,1.12579069142064,-1.2353622688409,-0.0845339362267303,-1.1066643511504,-1.35121160514622,0.102042903429512
98.4300319334168,-1.43946924667879,-0.220626178279708,1.1790978221381,0.362854136258717,-1.60656592948588,-1.42626271965008,1.35263732089601
85.9538774371038,0.299167085972092,-0.658333053474294,0.584198561755136,-0.902354368959755,-0.936233843988994,-0.802583835560661,-0.812436183014509
69.0428161242736,-0.125771615934187,0.254126091345437,-1.57853786911604,-1.70467126260809,-0.20036088837741,-0.611219839259338,-1.74679514919257
39.3466573440772,-1.11942732784344,1.02687217945684,-0.0790799687551167,-1.40057871814644,-0.421888388400576,-0.00360971250824016,-1.44145922137225
84.7552746992452,0.292133417257813,-1.11413695028762,0.0301869267116057,-0.707632663968324,-1.63236755406421,0.0519301216930788,0.512580786384611
53.0313342868092,-1.53253639882853,-1.45278700730094,-1.46758003155427,-0.138931242944589,0.80345794756676,-1.221195622646,-0.270973851546017
53.9907303505328,-0.127745184093581,1.13981001337361,-0.53626111333133,1.10182692748514,-0.945117324789316,-0.631750745913938,0.651331608011695
49.1299428490483,0.556117407877142,-0.259927047492294,-1.51322338924261,-1.34929517049896,1.51290610092806,1.69104877567221,-0.0554226533835236
54.9734393551028,0.825839134105828,0.928626020458063,-0.599430996328065,-1.60605462338764,-1.32142419038786,-0.276255477316723,-0.544738762486894
71.2284422100925,-1.42180765102755,-0.781498506310908,-0.713452115897049,-0.41563301205706,0.439113652329778,-1.61262998837178,-0.780505558348065
60.990107996041,-1.61922930382874,0.11563871248408,-0.216945487845601,-0.807124610500507,1.23547705044343,-1.54790657342152,-0.117743242436297
61.6044913512542,-1.12385406562549,-0.16349838780662,1.06299644410684,-0.547902601371806,0.111211221385257,1.636101437212,-0.96529482198221
80.8615082637375,-1.20023776201468,-0.997827246293255,-0.987771982863827,1.41795103531711,-1.65604935975795,-0.0705941609762963,2.18296981188907
62.8946325086022,-1.23981259576181,-1.51426072499125,1.68164409886969,1.43264426929433,0.700045832488443,1.30790272210221,0.702655679278482
55.9688555461239,-0.923675251654058,-1.00474225390427,-0.765370917674791,1.08018946381977,-0.845261356879923,0.851601909638055,0.397501435821256
44.7903778001622,-1.3277648520301,-0.678748692983859,-1.51834932839307,-1.38402343915436,0.164475545320623,1.2361867917943,-1.64899561117467
13.0724920760094,1.26568520552495,1.37837572731916,-0.103708728315572,1.6502056331237,1.57930185895323,1.62350361352673,1.95303672507995
77.9015017757493,-0.901201723318979,-1.07869713119193,0.522045940308766,0.97895834194872,-1.43573621685986,-0.771319547299304,1.27442207576582
87.8662032492901,-1.16614915850607,-1.07741997938722,-0.728892724801878,0.103863449418467,-1.59879375465689,-0.305319978165813,1.01702411214478
53.7898540526604,0.676658697861956,-0.0665656777375838,0.52924338605821,-0.820046717699875,0.829193234295671,0.131281875687316,-0.690631630764377
46.6525154828357,1.06449517912072,-1.11742050808806,-0.200529826519682,-1.00784518102146,-0.325352327035801,1.61001256020421,-1.17825837823084
69.7594973060135,-0.792354662420872,0.192782000598717,0.815339939649601,-1.14984637935976,0.46861161842573,-0.00852027081141471,-1.33778924481664
62.6428128155526,-0.301105283731258,1.48144463159779,1.09536901378075,-0.354953754818946,-1.05806648184761,0.313778114861242,-0.243663127780538
74.3461319371709,-0.850557343177548,-0.732485620763287,-0.565549824319711,1.07664970169396,-1.1213547081673,0.529227064732469,0.787809149307452
60.630326875821,-1.13933544558271,0.726923671703835,-0.286886260243726,-1.49544177587267,0.397418618200369,-0.472849648742755,-1.47033004464401
69.9735663664776,1.06838619979222,-1.23806058177582,-0.390841250555037,1.2701012855684,-1.38202223136699,0.113761854390127,1.44795718955396
41.7410825239741,0.872751787811526,-1.25866779441904,-0.751594260508981,-0.827697761772537,1.00868512196571,-0.365338647569303,-0.456970893126418
25.26849771872,-0.278794397616889,1.17222787561365,-0.283526406133255,-0.323943390768912,1.39742573740432,-1.22686477900624,0.45271368680852
60.7685410476345,-1.72275775150333,1.45286684758732,1.33299852031857,-0.495702135742685,-1.05408584551575,-0.859704675194392,-0.315863319312714
46.7245707013728,-0.0808035930225477,0.533578577301572,-0.898129324888319,0.00437974501060467,0.530754403200389,-0.811935978600038,-0.595306853483849
60.0141892489865,-0.990017349973675,-1.70652371291594,0.485342250850894,-0.454513244184767,0.180690314645644,0.253931513816726,-0.93325796774653
59.7943426000386,-1.45483742022369,1.08344188560228,0.639736294089738,0.0968756886672166,-0.724038316827594,0.789014954291541,-0.30985831128057
56.1595038956892,-1.20728014952374,1.28299414165486,-0.576288191205891,-1.1379840549745,-0.648494104875911,0.351418610186211,-1.1946401731152
40.7777395198107,-1.48048039096616,1.69722008944529,-0.903569932682152,0.0707544343625672,-0.634375814520276,1.33523315387421,-0.352728024519345
57.1293466731724,-0.764021476495531,0.0585628298920959,-1.01411612698704,0.355615332289204,0.0389919310999269,0.373434759902866,-0.366846525545614
38.3611748593373,-1.00269721098482,1.59132082322148,1.71113641186364,0.532429263514751,-0.611530802616558,1.60192210258574,-0.118766183052965
55.3383058682243,1.08184186980973,-1.1148366726867,-1.59418706691896,1.38307747250362,-0.469116981064329,-1.05645346448505,0.318792873907492
42.7879368861487,-0.699077862374198,1.01555980051319,-0.556840625855393,0.756932694674388,0.177405634935532,0.491387246144422,-0.169811394614183
13.6985700558202,1.3193016122991,0.396965094079659,-0.981716385483579,-0.599705175404643,1.45035565160278,-0.711920842276516,0.380336346802833
30.2674589212539,0.660148058937865,1.60047074184099,-1.29859065970928,-0.85634714071887,-0.710427001402027,0.971073584976346,-1.03047317100842
77.1663476461204,0.993011502665351,0.367364913221281,1.25372948679722,1.34411664274002,-1.30712278437147,0.902138963109443,1.27705120428023
55.9004278754475,-1.45845132436713,-0.746105935662694,-0.410043888748406,-0.00478969693421538,1.22929844546731,-1.42152488946297,0.353359563057347
62.1776501961913,-1.01814619670765,-0.225002141382011,0.552850127042247,-1.71298810482198,1.11206378381079,1.14491051638799,-1.10402466722037
-15.0298334104249,1.46704291427465,1.4360626651515,-1.3714434652052,1.37668672497448,0.685287763262609,-0.555303714457288,0.588943894059733
2.33500297700738,1.6883799066154,-1.23536906966214,-0.741185465678751,-1.08370211702685,1.63401092105943,0.481352965087457,0.435131143329713
45.3814955627723,-1.26937572940457,0.594058531440333,0.840816866954191,1.2807489882805,1.64098433572347,-1.11273225485542,1.86651206501023
45.384782184248,1.52297024526862,-0.905836023262231,1.70647595392294,0.507042538231651,-0.581409016029094,-0.588148119334049,-0.227202922938378
82.841656620862,-1.16162690354456,-0.908483369558739,1.34090291192001,-0.658420359178293,-0.913962069855705,-0.378855095893914,-0.484251234594375
44.3999645990312,0.504160173232586,1.45399602910433,1.1076290620001,1.70458814692619,-0.743701267864679,1.55918921329013,0.72713368513579
63.3539236746898,1.03016796212061,0.304498091014579,0.0158904567751568,-1.11843237463211,-0.80613527490302,-0.988752335925003,-0.994218435894059
5.6262949013419,1.14072965507125,1.72188816181752,0.244790682584893,0.297712309492292,-0.931681877375103,0.857964995762393,0.197439453469181
72.2750255276553,0.402921384306658,-1.19583209451894,1.22453864730485,-1.20563701804084,0.294291312514567,0.0707706113160353,-1.41820500439122
65.1661047039913,-1.65446705013579,-0.435687024833422,-1.14955624996999,1.42107944696333,0.494883310251489,1.19687768690978,0.309144969686369
53.7186211093843,0.16471225696955,0.572617454393101,0.184554821631586,-0.0208361056060542,-0.0492083551195348,1.57485701414593,-0.627013872076023
62.352327471058,1.09486686846614,-1.42758986700819,1.05164978521721,0.454910547806823,-1.47714683519267,-0.310621523199207,0.953680412655083
78.4434821994913,-0.704920393702809,-0.147291598477492,0.623006020578883,0.501010045254307,-1.54427527766181,1.53416114341368,1.1739994512146
62.9955911817325,0.910814463149627,-0.826204008005341,-1.03015043258445,0.232622779363593,-0.414499075933641,-1.0913782713898,-0.351921785532884
44.5611128464481,1.44773047733852,-1.45251460908458,1.17731592631788,-1.60943604058586,0.0392540377509425,1.04953613643253,-1.75654370402852
56.7670080713106,-0.952133296205245,-0.93649682090639,0.176957884092626,1.52240414707002,1.45518364993632,-0.22037005460924,1.84308825985746
84.8105548238883,-1.43998806416795,-0.773950099632352,0.878043854280969,-0.229947411134874,-1.59987966723924,-0.0864756932866715,0.956469952113227
30.7826099278841,0.516762186939956,1.00546739792155,-0.439315034712475,0.460860717939944,1.26076062375416,1.23084133178047,0.77858963816371
48.3096961725992,0.386994044045332,0.105098027533746,0.302087697525151,1.51513150998269,-0.24307556257021,-1.44570881627483,0.296433875701478
58.3783447482512,-1.43384998666643,1.24473395698241,1.56447484430503,-0.997878330687821,-1.44299636534234,-1.65261892373717,-0.0662626928957609
78.4569663704931,-1.25367635215507,-0.621193100851048,-1.7155193717786,0.833779363099376,-1.41983818497641,-1.65504806465176,1.23515542998154
77.2527380745147,-1.0967414028924,-1.15044042367497,0.938236375323292,1.31300852656323,-0.137889692977375,0.216750670771836,0.209862074926078
61.907979337834,0.406402738572903,0.622249438894337,-1.62615529583071,1.39367125499485,-0.880279357296441,1.2062644994583,0.687793954981192
34.2920779481112,0.958271322894185,0.950511079344682,-0.806882762747492,-0.986610554710896,0.140719262891426,-0.496602026668201,-1.27285285584761
24.6498590191877,1.43629468671794,0.0651166398539809,-0.0166276296643564,-0.290220545137522,1.09481982084937,-1.57684952894809,-0.110443754176291
55.890658815924,0.85683154276183,0.902198054116019,1.25852489974426,0.372444458059668,-1.36930676041056,0.597387238241185,0.708411407034193
83.6586425123829,-1.72247826856047,-0.280272603538844,-1.00779106561572,-0.853145388764738,-1.64103915121375,1.44267160112503,0.486833282080073
75.2443847583109,0.144141356775803,0.525642985158275,0.980518066585537,0.851234830633552,-1.52252259847054,-1.28585582512425,1.43856894216663
46.6372434162612,0.111590804319041,1.44692365732932,0.942841599981328,-1.01919945131408,-0.53288382969678,-0.823768552618565,-1.29050345772249
16.0526315261563,1.18323229962789,1.43802001683652,-1.56971120243444,1.13614704927362,-1.67734659524186,-0.755160344361692,1.95218858771372
63.706507020081,-0.82708893260745,-1.04227309082601,1.25207921735558,-1.43091247468544,0.957030532738442,-0.724422594683159,-1.08338859204456
48.1881091441847,-1.69563090318628,1.229925050166,-0.516997075788123,1.20039386634913,-1.43047364346802,1.14215743474263,1.39115887745719
60.6603587194682,0.206886177153248,0.608890910445989,-0.554754395704262,1.35456590294057,-1.67086309135052,-1.21657824813369,1.96919787028636
41.0999471314382,0.00322455228805985,1.31663446925717,-1.23875694570482,-1.11272672112267,-0.687457409131871,0.752669571004603,-1.16319939308833
21.2595558899763,1.22328100188792,0.620010517724166,0.133638800623307,-1.29335238844562,1.40585826697527,-0.775317413937645,-0.235719325532159

我在网上搜索了各种解决方案,但总是得到同样的错误:"列多于列名"。

jjhzyzn0

jjhzyzn01#

您的数据格式不正确,原因(至少)有两个:
1.标题行中的双引号,以及
1.标题行第一列中缺少一个引号。
这个 hack 可以修复它,尽管它一点也不漂亮。用文件的真实的路径替换quux.csv

dat <- read.csv(pipe("sed -E '1 { s/[\",]+/,/g; s/(^,|,$)//g; }' quux.csv"))
head(dat)
#   y_ImageQuality      x1_ISO  x2_FRatio    x3_TIME        x4_MP    x5_CROP    x6_FOCAL x7_PixDensity
# 1       74.73301 -1.40939052  0.1665579 -0.1555724  0.646076302 -1.6261774  0.95284746    1.41496914
# 2       67.54320 -0.07166044 -1.6659580 -0.1985845  0.001693124  0.7369829  1.02940846   -0.32078688
# 3      105.72950 -0.55722470 -1.4044613  0.6522771 -1.485322072 -1.5900569 -0.99408210    0.05225035
# 4       47.03300 -0.29165975  0.6248629 -0.6630446 -1.302953414  0.3636431 -0.06681617   -1.49598133
# 5       57.93967  1.33204133 -1.3140484 -0.3927121 -0.710038461 -1.4339213  1.22567317    0.25748674
# 6       76.49994  0.98508947 -0.3488143  1.3258127  0.837713623 -1.5922409 -1.05322679    1.64741702

sed表达式对于regex来说并不太复杂,下面是一个简短的演练:

sed -E '1 { s/[\",]+/,/g; s/(^,|,$)//g; }'
    ^^                                      support extended regex
        ^ ^-----------------------------^   first line only run the {.} code
            ^^^^^^^^^^^^                    replace repeated " or , with a single ,
                          ^^^^^^^^^^^^^     remove leading-comma or trailing comma

pipe命令在子命令中运行此命令,并将输出通过管道传输到read.csv
如果您发现无法找到sed的错误,

'sed' is not recognized as an internal or external command,

那么你可能需要在你的路径中找到它(在linux上应该会自动找到,可能是macos),在windows上,可能是c:/rtools40/usr/bin/sed.exe(或者rtools42,取决于你的R版本)。

相关问题