简体   繁体   中英

R novice starting to copy the example from the doc - but does not work

I am a novice on R and try to follow the simple example to read a csv and convert it. example from the doc for import

I run R on ubuntu. I have created the file in EXCEL and exported a csv, changed ";" by " " and moved it to the ubuntu and started R

zz <- read.csv("mr.csv", strip.white = TRUE)

result:

print(zz)
            Status.Age.V1.V2.V3.V4
1  P 23646 45190 50333 55166 56271
2 CC 26174 35535 38227 37911 41184
3 CC 27723 25691 25712 26144 26398
4 CC 27193 30949 29693 29754 30772
5 CC 24370 50542 51966 54341 54273
6 CC 28359 58591 58803 59435 61292
7 CC 25136 45801 45389 47197 47126

then

Fehler in `[.data.frame`(zz, gl(nrow(zz), 1, 4 * nrow(zz)), 1:2) : 
  nicht definierte Spalten gewählt

I appreciate any help what might be wrong.

Regards Kallewirsch

The concatenated header indicates that you are only getting one giant column for each row. I think what is happening is that European conventions for delimited text files are being used by your installation of Excel, so the file is not "CSV" but rather "semicolon separated. You should try this (after going back to the original exported file and not attempting any substitution of space for commas prior to the import:

zz <- read.delim("mr.csv")

read.delim also has the parameter dec="," for The European convention of decimal point as a comma so there's no need to do the any swapping of period for commas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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