hi R-users, I have a file as shown below,and the first column is time information. "2012-08-07 00:00:00",4174830,5,8.1,34.5,9.5,32,14 "2012-08-07 00:00:01",4174831,4.7,8.6,34.5,9.9,29,14 "2012-08-07 00:00:02",4174832,4.7,8.6,34.5,9.9,29,14 "2012-08-07 00:00:03",4174833,5,8.5,34.5,9.8,30,14 "2012-08-07 00:00:04",4174834,5,8.5,34.5,9.8,30,14 "2012-08-07 00:00:05",4174835,5.4,8.3,34.6,9.9,33,14 "2012-08-07 00:00:06",4174836,5.4,8.3,34.6,9.9,33,14 "2012-08-07 00:00:07",4174837,5.1,7.8,34.5,9.3,33,14 "2012-08-07 00:00:08",4174838,5.1,7.8,34.5,9.3,33,14 "2012-08-07 00:00:09",4174839,5.3,7.8,34.5,9.4,34,14 "2012-08-07 00:00:10",4174840,5.3,7.8,34.5,9.4,34,14 "2012-08-07 00:00:11",4174841,5.4,8.3,34.5,9.9,33,14 "2012-08-07 00:00:12",4174842,5.4,8.3,34.5,9.9,33,14 "2012-08-07 00:00:13",4174843,5.6,8.3,34.5,10,34,14 "2012-08-07 00:00:14",4174844,5.6,8.3,34.5,10,34,14 "2012-08-07 00:00:15",4174845,5.5,8.1,34.5,9.8,34,14 "2012-08-07 00:00:16",4174846,5.5,8.1,34.5,9.8,34,14 "2012-08-07 00:00:17",4174847,4.3,7.4,34.4,8.6,30,14 I want to read them into a array by such command wnd_data<-scan("obs.dat",sep=",",what=list(TIME="",rec=0,U=0,V=0,T=0,WS=0,WD=0,ST=0,TA=0,RH=0),na.strings = "NAN") but R could not excute sucefully and says that : error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : scan() require 'a real', but not "2012-08-0700:00:01"' How could I resolve this problem ? Thanks. -- TANG Jie [[alternative HTML version deleted]]
On 2013/6/1 15:54, Jie Tang wrote:> hi R-users, > I have a file as shown below,and the first column is time information. > > "2012-08-07 00:00:00",4174830,5,8.1,34.5,9.5,32,14 > "2012-08-07 00:00:01",4174831,4.7,8.6,34.5,9.9,29,14 > "2012-08-07 00:00:02",4174832,4.7,8.6,34.5,9.9,29,14 > "2012-08-07 00:00:03",4174833,5,8.5,34.5,9.8,30,14 > "2012-08-07 00:00:04",4174834,5,8.5,34.5,9.8,30,14 > "2012-08-07 00:00:05",4174835,5.4,8.3,34.6,9.9,33,14 > "2012-08-07 00:00:06",4174836,5.4,8.3,34.6,9.9,33,14 > "2012-08-07 00:00:07",4174837,5.1,7.8,34.5,9.3,33,14 > "2012-08-07 00:00:08",4174838,5.1,7.8,34.5,9.3,33,14 > "2012-08-07 00:00:09",4174839,5.3,7.8,34.5,9.4,34,14 > "2012-08-07 00:00:10",4174840,5.3,7.8,34.5,9.4,34,14 > "2012-08-07 00:00:11",4174841,5.4,8.3,34.5,9.9,33,14 > "2012-08-07 00:00:12",4174842,5.4,8.3,34.5,9.9,33,14 > "2012-08-07 00:00:13",4174843,5.6,8.3,34.5,10,34,14 > "2012-08-07 00:00:14",4174844,5.6,8.3,34.5,10,34,14 > "2012-08-07 00:00:15",4174845,5.5,8.1,34.5,9.8,34,14 > "2012-08-07 00:00:16",4174846,5.5,8.1,34.5,9.8,34,14 > "2012-08-07 00:00:17",4174847,4.3,7.4,34.4,8.6,30,14 > > I want to read them into a array by such command > > wnd_data<-scan("obs.dat",sep=",",what=list(TIME="",rec=0,U=0,V=0,T=0,WS=0,WD=0,ST=0,TA=0,RH=0),na.strings > = "NAN")wnd_data <- read.table("obs.dat", header = FALSE, sep = ",") colnames(wnd_data) <- c("TIME","rec","U","V","T","WS","WD","ST","TA","RH") HIH...> > but R could not excute sucefully and says that : > error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, > : > scan() require 'a real', but not "2012-08-0700:00:01"' > > How could I resolve this problem ? > Thanks. >
Hello, Just use ?read.csv with argument header = FALSE. wnd_data <- read.csv(text = ' "2012-08-07 00:00:00",4174830,5,8.1,34.5,9.5,32,14 "2012-08-07 00:00:01",4174831,4.7,8.6,34.5,9.9,29,14 "2012-08-07 00:00:02",4174832,4.7,8.6,34.5,9.9,29,14 "2012-08-07 00:00:03",4174833,5,8.5,34.5,9.8,30,14 "2012-08-07 00:00:04",4174834,5,8.5,34.5,9.8,30,14 "2012-08-07 00:00:05",4174835,5.4,8.3,34.6,9.9,33,14 "2012-08-07 00:00:06",4174836,5.4,8.3,34.6,9.9,33,14 "2012-08-07 00:00:07",4174837,5.1,7.8,34.5,9.3,33,14 "2012-08-07 00:00:08",4174838,5.1,7.8,34.5,9.3,33,14 "2012-08-07 00:00:09",4174839,5.3,7.8,34.5,9.4,34,14 "2012-08-07 00:00:10",4174840,5.3,7.8,34.5,9.4,34,14 "2012-08-07 00:00:11",4174841,5.4,8.3,34.5,9.9,33,14 "2012-08-07 00:00:12",4174842,5.4,8.3,34.5,9.9,33,14 "2012-08-07 00:00:13",4174843,5.6,8.3,34.5,10,34,14 "2012-08-07 00:00:14",4174844,5.6,8.3,34.5,10,34,14 "2012-08-07 00:00:15",4174845,5.5,8.1,34.5,9.8,34,14 "2012-08-07 00:00:16",4174846,5.5,8.1,34.5,9.8,34,14 "2012-08-07 00:00:17",4174847,4.3,7.4,34.4,8.6,30,14 ', header = FALSE) str(wnd_data) Note also that your vector of column names is of length 10 and there are only 8 columns. Hope this helps, Rui Barradas Em 01-06-2013 08:54, Jie Tang escreveu:> hi R-users, > I have a file as shown below,and the first column is time information. > > "2012-08-07 00:00:00",4174830,5,8.1,34.5,9.5,32,14 > "2012-08-07 00:00:01",4174831,4.7,8.6,34.5,9.9,29,14 > "2012-08-07 00:00:02",4174832,4.7,8.6,34.5,9.9,29,14 > "2012-08-07 00:00:03",4174833,5,8.5,34.5,9.8,30,14 > "2012-08-07 00:00:04",4174834,5,8.5,34.5,9.8,30,14 > "2012-08-07 00:00:05",4174835,5.4,8.3,34.6,9.9,33,14 > "2012-08-07 00:00:06",4174836,5.4,8.3,34.6,9.9,33,14 > "2012-08-07 00:00:07",4174837,5.1,7.8,34.5,9.3,33,14 > "2012-08-07 00:00:08",4174838,5.1,7.8,34.5,9.3,33,14 > "2012-08-07 00:00:09",4174839,5.3,7.8,34.5,9.4,34,14 > "2012-08-07 00:00:10",4174840,5.3,7.8,34.5,9.4,34,14 > "2012-08-07 00:00:11",4174841,5.4,8.3,34.5,9.9,33,14 > "2012-08-07 00:00:12",4174842,5.4,8.3,34.5,9.9,33,14 > "2012-08-07 00:00:13",4174843,5.6,8.3,34.5,10,34,14 > "2012-08-07 00:00:14",4174844,5.6,8.3,34.5,10,34,14 > "2012-08-07 00:00:15",4174845,5.5,8.1,34.5,9.8,34,14 > "2012-08-07 00:00:16",4174846,5.5,8.1,34.5,9.8,34,14 > "2012-08-07 00:00:17",4174847,4.3,7.4,34.4,8.6,30,14 > > I want to read them into a array by such command > > wnd_data<-scan("obs.dat",sep=",",what=list(TIME="",rec=0,U=0,V=0,T=0,WS=0,WD=0,ST=0,TA=0,RH=0),na.strings > = "NAN") > > but R could not excute sucefully and says that : > error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, > : > scan() require 'a real', but not "2012-08-0700:00:01"' > > How could I resolve this problem ? > Thanks. >