[R] Deletion of rows
arun
smartpink111 at yahoo.com
Mon Mar 17 08:37:07 CET 2014
Hi Dila,
Suppose 'dat' is the dataset:
str(dat)
#'data.frame': 621 obs. of 5 variables:
# $ V1: int NA 8185 8186 8187 8188 8189 8190 8191 8192 8193 ...
# $ V2: Factor w/ 3 levels "1948","1949",..: 3 1 1 1 1 1 1 1 1 1 ...
# $ V3: Factor w/ 32 levels "1","10","11",..: 32 1 12 23 26 27 28 29 30 31 ...
# $ V4: Factor w/ 13 levels "1","10","11",..: 13 8 8 8 8 8 8 8 8 8 ...
# $ V5: Factor w/ 119 levels "","0","0.2","0.5",..: 119 29 2 60 103 77 112 2 114 50 ...
which(is.na(dat$V5))
#integer(0)
Based on the dput() data, your first row is the column name, probably you read using:
read.table(..., header=FALSE). Also, I would assume that the first column is infact the row.names.
head(dat,3)
# V1 V2 V3 V4 V5
#1 NA Year Day Month Amount
#2 8185 1948 1 5 16.2
#3 8186 1948 2 5 0
dat1 <- dat[-1,-1]
names(dat1) <- as.character(unlist(dat[1,-1]))
row.names(dat1) <- as.character(dat[-1,1])
dat1[] <- lapply(dat1,function(x) as.numeric(as.character(x)))
dat[590,]
# V1 V2 V3 V4 V5
#590 20522 1949 31 11
dat1[589,]
# Year Day Month Amount
#20522 1949 31 11 NA
which(is.na(dat$V5))
#integer(0)
which(dat$V5=="")
# [1] 63 156 218 309 310 311 373 435 528 590
which(is.na(dat1$Amount)) ##because first row was deleted
# [1] 62 155 217 308 309 310 372 434 527 589
dat2 <- dat1[!is.na(dat1$Amount),]
which(is.na(dat2$Amount)) ###no NAs
#integer(0)
which(row.names(dat2)=="20522")
#integer(0)
A.K.
On Monday, March 17, 2014 3:11 AM, dila radi <dilaradi21 at gmail.com> wrote:
Dear Arun,
Can you read this data? This is part of my data. If you can seen, in the 5th column (Amount), there are some blank data(Eg: 31/6/1948) which supposed to be deleted. How can I achieved this?
structure(list(V1 = c(NA, 8185L, 8186L, 8187L, 8188L, 8189L,
8190L, 8191L, 8192L, 8193L, 8194L, 8195L, 8196L, 8197L, 8198L,
8199L, 8200L, 8201L, 8202L, 8203L, 8204L, 8205L, 8206L, 8207L,
8208L, 8209L, 8210L, 8211L, 8212L, 8213L, 8214L, 8215L, 10231L,
10232L, 10233L, 10234L, 10235L, 10236L, 10237L, 10238L, 10239L,
10240L, 10241L, 10242L, 10243L, 10244L, 10245L, 10246L, 10247L,
10248L, 10249L, 10250L, 10251L, 10252L, 10253L, 10254L, 10255L,
10256L, 10257L, 10258L, 10259L, 10260L, 10261L, 12277L, 12278L,
12279L, 12280L, 12281L, 12282L, 12283L, 12284L, 12285L, 12286L,
12287L, 12288L, 12289L, 12290L, 12291L, 12292L, 12293L, 12294L,
12295L, 12296L, 12297L, 12298L, 12299L, 12300L, 12301L, 12302L,
12303L, 12304L, 12305L, 12306L, 12307L, 14323L, 14324L, 14325L,
14326L, 14327L, 14328L, 14329L, 14330L, 14331L, 14332L, 14333L,
14334L, 14335L, 14336L, 14337L, 14338L, 14339L, 14340L, 14341L,
14342L, 14343L, 14344L, 14345L, 14346L, 14347L, 14348L, 14349L,
14350L, 14351L, 14352L, 14353L, 16369L, 16370L, 16371L, 16372L,
16373L, 16374L, 16375L, 16376L, 16377L, 16378L, 16379L, 16380L,
16381L, 16382L, 16383L, 16384L, 16385L, 16386L, 16387L, 16388L,
16389L, 16390L, 16391L, 16392L, 16393L, 16394L, 16395L, 16396L,
16397L, 16398L, 16399L, 18415L, 18416L, 18417L, 18418L, 18419L,
18420L, 18421L, 18422L, 18423L, 18424L, 18425L, 18426L, 18427L,
18428L, 18429L, 18430L, 18431L, 18432L, 18433L, 18434L, 18435L,
18436L, 18437L, 18438L, 18439L, 18440L, 18441L, 18442L, 18443L,
18444L, 18445L, 20461L, 20462L, 20463L, 20464L, 20465L, 20466L,
20467L, 20468L, 20469L, 20470L, 20471L, 20472L, 20473L, 20474L,
20475L, 20476L, 20477L, 20478L, 20479L, 20480L, 20481L, 20482L,
20483L, 20484L, 20485L, 20486L, 20487L, 20488L, 20489L, 20490L,
20491L, 22507L, 22508L, 22509L, 22510L, 22511L, 22512L, 22513L,
22514L, 22515L, 22516L, 22517L, 22518L, 22519L, 22520L, 22521L,
22522L, 22523L, 22524L, 22525L, 22526L, 22527L, 22528L, 22529L,
22530L, 22531L, 22532L, 22533L, 22534L, 22535L, 22536L, 22537L,
32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L,
45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L,
58L, 59L, 60L, 61L, 62L, 2078L, 2079L, 2080L, 2081L, 2082L, 2083L,
2084L, 2085L, 2086L, 2087L, 2088L, 2089L, 2090L, 2091L, 2092L,
2093L, 2094L, 2095L, 2096L, 2097L, 2098L, 2099L, 2100L, 2101L,
2102L, 2103L, 2104L, 2105L, 2106L, 2107L, 2108L, 4124L, 4125L,
4126L, 4127L, 4128L, 4129L, 4130L, 4131L, 4132L, 4133L, 4134L,
4135L, 4136L, 4137L, 4138L, 4139L, 4140L, 4141L, 4142L, 4143L,
4144L, 4145L, 4146L, 4147L, 4148L, 4149L, 4150L, 4151L, 4152L,
4153L, 4154L, 6170L, 6171L, 6172L, 6173L, 6174L, 6175L, 6176L,
6177L, 6178L, 6179L, 6180L, 6181L, 6182L, 6183L, 6184L, 6185L,
6186L, 6187L, 6188L, 6189L, 6190L, 6191L, 6192L, 6193L, 6194L,
6195L, 6196L, 6197L, 6198L, 6199L, 6200L, 8216L, 8217L, 8218L,
8219L, 8220L, 8221L, 8222L, 8223L, 8224L, 8225L, 8226L, 8227L,
8228L, 8229L, 8230L, 8231L, 8232L, 8233L, 8234L, 8235L, 8236L,
8237L, 8238L, 8239L, 8240L, 8241L, 8242L, 8243L, 8244L, 8245L,
8246L, 10262L, 10263L, 10264L, 10265L, 10266L, 10267L, 10268L,
10269L, 10270L, 10271L, 10272L, 10273L, 10274L, 10275L, 10276L,
10277L, 10278L, 10279L, 10280L, 10281L, 10282L, 10283L, 10284L,
10285L, 10286L, 10287L, 10288L, 10289L, 10290L, 10291L, 10292L,
12308L, 12309L, 12310L, 12311L, 12312L, 12313L, 12314L, 12315L,
12316L, 12317L, 12318L, 12319L, 12320L, 12321L, 12322L, 12323L,
12324L, 12325L, 12326L, 12327L, 12328L, 12329L, 12330L, 12331L,
12332L, 12333L, 12334L, 12335L, 12336L, 12337L, 12338L, 14354L,
14355L, 14356L, 14357L, 14358L, 14359L, 14360L, 14361L, 14362L,
14363L, 14364L, 14365L, 14366L, 14367L, 14368L, 14369L, 14370L,
14371L, 14372L, 14373L, 14374L, 14375L, 14376L, 14377L, 14378L,
14379L, 14380L, 14381L, 14382L, 14383L, 14384L, 16400L, 16401L,
16402L, 16403L, 16404L, 16405L, 16406L, 16407L, 16408L, 16409L,
16410L, 16411L, 16412L, 16413L, 16414L, 16415L, 16416L, 16417L,
16418L, 16419L, 16420L, 16421L, 16422L, 16423L, 16424L, 16425L,
16426L, 16427L, 16428L, 16429L, 16430L, 18446L, 18447L, 18448L,
18449L, 18450L, 18451L, 18452L, 18453L, 18454L, 18455L, 18456L,
18457L, 18458L, 18459L, 18460L, 18461L, 18462L, 18463L, 18464L,
18465L, 18466L, 18467L, 18468L, 18469L, 18470L, 18471L, 18472L,
18473L, 18474L, 18475L, 18476L, 20492L, 20493L, 20494L, 20495L,
20496L, 20497L, 20498L, 20499L, 20500L, 20501L, 20502L, 20503L,
20504L, 20505L, 20506L, 20507L, 20508L, 20509L, 20510L, 20511L,
20512L, 20513L, 20514L, 20515L, 20516L, 20517L, 20518L, 20519L,
20520L, 20521L, 20522L, 22538L, 22539L, 22540L, 22541L, 22542L,
22543L, 22544L, 22545L, 22546L, 22547L, 22548L, 22549L, 22550L,
22551L, 22552L, 22553L, 22554L, 22555L, 22556L, 22557L, 22558L,
22559L, 22560L, 22561L, 22562L, 22563L, 22564L, 22565L, 22566L,
22567L, 22568L), V2 = structure(c(3L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L,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 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1948", "1949", "Year"), class = "factor"),
V3 = structure(c(32L, 1L, 12L, 23L, 26L, 27L, 28L, 29L, 30L,
31L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 1L, 12L,
23L, 26L, 27L, 28L, 29L, 30L, 31L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 24L, 25L, 1L, 12L, 23L, 26L, 27L, 28L, 29L, 30L,
31L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 1L, 12L,
23L, 26L, 27L, 28L, 29L, 30L, 31L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 24L, 25L, 1L, 12L, 23L, 26L, 27L, 28L, 29L, 30L,
31L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 1L, 12L,
23L, 26L, 27L, 28L, 29L, 30L, 31L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 24L, 25L, 1L, 12L, 23L, 26L, 27L, 28L, 29L, 30L,
31L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 1L, 12L,
23L, 26L, 27L, 28L, 29L, 30L, 31L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 24L, 25L, 1L, 12L, 23L, 26L, 27L, 28L, 29L, 30L,
31L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 1L, 12L,
23L, 26L, 27L, 28L, 29L, 30L, 31L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 24L, 25L, 1L, 12L, 23L, 26L, 27L, 28L, 29L, 30L,
31L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 1L, 12L,
23L, 26L, 27L, 28L, 29L, 30L, 31L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 24L, 25L, 1L, 12L, 23L, 26L, 27L, 28L, 29L, 30L,
31L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 1L, 12L,
23L, 26L, 27L, 28L, 29L, 30L, 31L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 24L, 25L, 1L, 12L, 23L, 26L, 27L, 28L, 29L, 30L,
31L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 1L, 12L,
23L, 26L, 27L, 28L, 29L, 30L, 31L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 24L, 25L, 1L, 12L, 23L, 26L, 27L, 28L, 29L, 30L,
31L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 1L, 12L,
23L, 26L, 27L, 28L, 29L, 30L, 31L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 24L, 25L, 1L, 12L, 23L, 26L, 27L, 28L, 29L, 30L,
31L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 1L, 12L,
23L, 26L, 27L, 28L, 29L, 30L, 31L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 24L, 25L), .Label = c("1", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "2", "20", "21", "22",
"23", "24", "25", "26", "27", "28", "29", "3", "30", "31",
"4", "5", "6", "7", "8", "9", "Day"), class = "factor"),
V4 = structure(c(13L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,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
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("1",
"10", "11", "12", "2", "3", "4", "5", "6", "7", "8", "9",
"Month"), class = "factor"), V5 = structure(c(119L, 29L,
2L, 60L, 103L, 77L, 112L, 2L, 114L, 50L, 39L, 18L, 2L, 2L,
15L, 43L, 35L, 40L, 16L, 2L, 108L, 7L, 2L, 2L, 30L, 2L, 26L,
39L, 2L, 2L, 13L, 61L, 2L, 103L, 114L, 105L, 2L, 2L, 2L,
2L, 2L, 109L, 78L, 2L, 109L, 14L, 2L, 3L, 39L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 107L, 2L, 105L, 51L, 2L, 26L, 1L, 49L, 35L,
2L, 109L, 114L, 103L, 65L, 4L, 22L, 103L, 2L, 2L, 2L, 2L,
2L, 61L, 48L, 2L, 2L, 2L, 2L, 2L, 5L, 2L, 103L, 69L, 2L,
2L, 90L, 9L, 8L, 2L, 78L, 2L, 79L, 33L, 2L, 118L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 18L, 70L, 2L, 2L, 2L, 7L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 88L, 4L, 2L, 3L, 52L, 2L, 109L, 112L,
92L, 2L, 2L, 19L, 43L, 26L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 39L,
2L, 64L, 45L, 92L, 2L, 2L, 2L, 2L, 114L, 2L, 1L, 2L, 2L,
2L, 2L, 113L, 103L, 2L, 2L, 9L, 56L, 2L, 2L, 100L, 103L,
2L, 2L, 8L, 2L, 2L, 2L, 2L, 103L, 2L, 28L, 2L, 58L, 2L, 54L,
2L, 2L, 106L, 35L, 2L, 3L, 5L, 103L, 52L, 2L, 2L, 114L, 4L,
7L, 14L, 7L, 103L, 12L, 8L, 2L, 114L, 67L, 108L, 34L, 19L,
10L, 111L, 14L, 62L, 103L, 61L, 39L, 2L, 1L, 2L, 2L, 2L,
81L, 35L, 2L, 83L, 2L, 2L, 114L, 2L, 2L, 103L, 27L, 2L, 2L,
2L, 72L, 99L, 32L, 86L, 56L, 85L, 74L, 109L, 37L, 2L, 103L,
2L, 2L, 2L, 114L, 92L, 2L, 2L, 2L, 2L, 7L, 11L, 114L, 107L,
2L, 2L, 2L, 2L, 2L, 79L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 75L, 92L, 2L, 2L,
2L, 2L, 2L, 35L, 2L, 2L, 2L, 80L, 104L, 7L, 2L, 2L, 25L,
2L, 54L, 2L, 2L, 2L, 57L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 110L, 92L, 111L, 40L, 70L, 49L, 40L, 2L,
2L, 114L, 2L, 76L, 2L, 2L, 61L, 2L, 2L, 103L, 22L, 98L, 2L,
3L, 3L, 2L, 2L, 66L, 73L, 6L, 9L, 2L, 41L, 47L, 28L, 117L,
2L, 23L, 9L, 21L, 40L, 38L, 78L, 2L, 97L, 2L, 2L, 112L, 5L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 101L, 2L, 94L, 2L, 64L, 2L,
93L, 58L, 2L, 2L, 2L, 39L, 34L, 59L, 39L, 7L, 2L, 36L, 29L,
2L, 108L, 2L, 2L, 2L, 116L, 2L, 2L, 63L, 92L, 2L, 2L, 37L,
2L, 110L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 65L, 103L, 42L,
2L, 2L, 2L, 2L, 2L, 46L, 30L, 38L, 7L, 114L, 20L, 84L, 2L,
92L, 2L, 2L, 1L, 8L, 2L, 92L, 37L, 4L, 43L, 87L, 2L, 2L,
2L, 24L, 8L, 2L, 2L, 41L, 2L, 7L, 2L, 2L, 103L, 4L, 2L, 2L,
2L, 57L, 2L, 2L, 2L, 2L, 2L, 103L, 61L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 30L, 43L, 117L, 2L, 23L, 2L, 2L, 2L,
93L, 54L, 30L, 49L, 61L, 103L, 2L, 102L, 3L, 5L, 58L, 82L,
61L, 19L, 2L, 2L, 2L, 114L, 3L, 114L, 68L, 97L, 96L, 8L,
57L, 9L, 35L, 2L, 2L, 114L, 4L, 2L, 2L, 109L, 103L, 3L, 2L,
58L, 2L, 49L, 14L, 22L, 1L, 2L, 59L, 2L, 2L, 6L, 22L, 58L,
61L, 70L, 48L, 44L, 2L, 7L, 3L, 37L, 2L, 2L, 30L, 95L, 19L,
2L, 2L, 2L, 38L, 2L, 2L, 30L, 109L, 24L, 5L, 2L, 2L, 22L,
47L, 2L, 2L, 2L, 2L, 2L, 79L, 2L, 2L, 2L, 2L, 2L, 89L, 2L,
2L, 2L, 115L, 47L, 2L, 9L, 91L, 53L, 55L, 37L, 2L, 2L, 5L,
2L, 1L, 2L, 49L, 103L, 17L, 2L, 2L, 61L, 114L, 54L, 114L,
71L, 61L, 86L, 2L, 31L, 2L, 2L, 7L, 37L, 39L, 2L, 61L, 2L,
22L, 7L, 5L, 41L, 2L, 116L, 2L, 2L), .Label = c("", "0",
"0.2", "0.5", "0.7", "1", "1.2", "1.5", "1.7", "10.1", "104.9",
"107.1", "108.7", "11.4", "11.6", "11.9", "12.1", "12.4",
"12.6", "13.2", "13.4", "13.9", "14.4", "14.7", "14.9", "15.2",
"15.7", "16", "16.2", "16.5", "17.2", "18", "18.2", "18.7",
"19", "19.3", "2", "2.2", "2.5", "2.7", "20.3", "20.5", "21.5",
"21.8", "22.3", "22.8", "23.3", "23.6", "24.1", "24.3", "25.1",
"25.3", "25.9", "26.6", "27.9", "28.9", "29.2", "3", "3.3",
"3.5", "3.8", "31.7", "32", "32.5", "33", "33.5", "33.7",
"34", "34.2", "36.8", "37.3", "38", "38.3", "38.6", "39.3",
"4", "4.3", "4.5", "4.8", "40.6", "41.4", "41.9", "42.9",
"43.1", "43.9", "44.4", "45.4", "45.7", "46.2", "46.9", "48.2",
"5", "5.3", "5.5", "5.8", "50.7", "52", "52.5", "55.6", "57.1",
"57.9", "59.6", "6.3", "6.6", "6.8", "64.7", "7.1", "7.3",
"7.6", "7.8", "8.1", "8.3", "8.6", "8.8", "87.1", "9.1",
"9.6", "9.9", "Amount"), class = "factor")), .Names = c("V1",
"V2", "V3", "V4", "V5"), row.names = c(NA, 621L), class = "data.frame")
Dila
On 16 March 2014 23:36, arun <smartpink111 at yahoo.com> wrote:
Also, are you talking about the example you provided or in your original dataset?. If it is in your original dataset, there must be something else going on. Check ?str() i.e. str(dataset). If you can provide a reproducible example, it will be great. From the example you provided, I can't find any NAs in res2.
>
>
>
>
>
>
>
>On , arun <smartpink111 at yahoo.com> wrote:
>Dear Dila,
>
>This is what I get:
>
>
>which(is.na(res1[,4])) #NA rows
>#[1] 60 61 62 124 186 279 341
>res1[is.na(res1[,4]),]
> Year Day Month Amount
>69 1949 29 2 NA
>70 1949 30 2 NA
>71 1949 31 2 NA
>151 1949 31 4 NA
>231 1949 31 6 NA
>351 1949 31 9 NA
>431 1949 31 11 NA
>
>
>res2 <- res1[!is.na(res1$Amount),]
>
>
> which(is.na(res2[,4]))
>#integer(0)
> res2[is.na(res2[,4]),] #no NA rows
>#[1] Year Day Month Amount
>#<0 rows> (or 0-length row.names)
>
>A.K.
>
>
>
>On Monday, March 17, 2014 2:21 AM, dila radi <dilaradi21 at gmail.com> wrote:
>
>Dear Arun,
>
>I tried to run using the command u gave earlier but it didn't works. Rows that have empty value should be automatically deleted, but it doesn't seems to perform that way. Is there any other way to solve this problem? Thank you so much
>
>Dila
>
>
>
>On 14 March 2014 07:18, arun <smartpink111 at yahoo.com> wrote:
>
>Hi,
>>
>>
>>Try:
>> res2 <- res1[!is.na(res1$Amount),]
>>A.K.
>>
>>
>>
>>
>>
>>
>>
>>On Friday, March 14, 2014 3:41 AM, dila radi <dilaradi21 at gmail.com> wrote:
>>
>>Hi all,
>> Regarding the previous post, here is part of my data.
>>
>>structure(list(Year = c(1949L, 1949L, 1949L, 1949L, 1949L, 1949L,
>>1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L,
>>1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L,
>>1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1950L, 1950L,
>>1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L), Day = c(1L,
>>2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
>>16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L,
>>29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), Jan = c(8.8,
>>5, 0, 0, 0, 0, 1.2, 104.9, 8.8, 7.1, 0, 0, 0, 0, 0, 4.8, 0, 0,
>>0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 53.3, 0, 36.8, 0, 17.2,
>>0, 19.8, 7.1), Feb = c(0, 0, 0.2, 39.3, 5, 0, 0, 0, 0, 0, 19,
>>0, 0, 0, 40.6, 6.6, 1.2, 0, 0, 14.9, 0, 26.6, 0, 0, 0, 29.2,
>>0, 0, NA, NA, NA, 0, 0, 24.3, 11.1, 27.1, 3.5, 0, 0, 0), Mar = c(0,
>>0, 0, 0, 0, 0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 1.7, 19, 0, 0, 8.8, 0.5, 0, 0, 7.6, 6.3, 0.2,
>>0, 3, 0, 24.1, 11.4, 13.9, NA, 1.2, 30.2, 6, 0, 0, 0, 0, 0, 0
>>), Oct = c(0, 3.3, 0, 0, 1, 13.9, 3, 3.8, 36.8, 23.6, 21.8, 0,
>>1.2, 0.2, 2, 0, 0, 16.5, 5.8, 12.6, 0, 0, 0, 2.2, 0, 0, 16.5,
>>7.6, 14.7, 0.7, 0, 0, 2.2, 0.5, 0, 0, 5, 0.2, 9.6, 16.5), Nov = c(0,
>>13.9, 23.3, 0, 0, 0, 0, 0, 4.8, 0, 0, 0, 0, 0, 46.2, 0, 0, 0,
>>87.1, 23.3, 0, 1.7, 48.2, 25.9, 27.9, 2, 0, 0, 0.7, 0, NA, 11.4,
>>0, 16.5, 8.6, 0, 3.8, 0, 1.2, 38), Dec = c(0, 24.1, 6.3, 12.1,
>>0, 0, 3.8, 8.8, 26.6, 8.8, 37.3, 3.8, 44.4, 0, 17.2, 0, 0, 1.2,
>>2, 2.5, 0, 3.8, 0, 13.9, 1.2, 0.7, 20.3, 0, 9.1, 0, 0, 0.5, 0,
>>0.5, 7.6, 0, 0, 1.2, 1.5, 0)), .Names = c("Year", "Day", "Jan",
>>"Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
>>"Nov", "Dec"), row.names = c(NA, 40L), class = "data.frame")
>>
>>
>>But data that is left blank is the one that I want to delete so that when I rearrange it column by column, it wont appear anymore.
>>
>>
>>Using this command, I can rearrange the data column by column
>>
>>
>>library(reshape2)
>>res <- transform(melt(dat,id.var=c("Year","Day")),Month=match(variable,month.abb),Amount=value)[,-c(3:4)]
>>
>>res1 <- res[with(res,order(Year,Month,Day)),]
>>
>>So, how do I rearrange it by excluding the empty row?
>>
>>Thank you for your help.
>>
>>Dila
>>
>>
>>
>>On 11 March 2014 01:42, PIKAL Petr <petr.pikal at precheza.cz> wrote:
>>
>>Hi
>>>
>>>No attachments allowed (mostly). Use ?dput and copy to email directly.
>>>
>>>How you can have more than 29 rows in February if each row is one day?
>>>
>>>I believe that merging your data with date column made by ?seq.POSIXt can remove any nonexistent row but it all depends on how your data are structured and what do you want to remove.
>>>
>>>Petr
>>>
>>>
>>>
>>>> -----Original Message-----
>>>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>>>> project.org] On Behalf Of dila radi
>>>> Sent: Tuesday, March 11, 2014 6:04 AM
>>>> To: r-help at r-project.org
>>>> Subject: [R] Deletion of rows
>>>>
>>>> Hi,
>>>>
>>>> I would like to ask about the deletion of rows in the data.
>>>>
>>>> Assuming I have this kind of data set, which you can refer through the
>>>> attachment.
>>>>
>>>>
>>>> As in the attachment, I have 31 days for each month which is I want to
>>>> delete some of the rows according to the real days per month.
>>>>
>>>> For example:
>>>>
>>>> Jan, March, May, July, Aug, Oct, Dec (these months have 31 days per
>>>> month, so no deletion of rows needed)
>>>>
>>>> Feb (28 days except for leap years), Apr, June, Sept, Nov (we have 30
>>>> days per month)
>>>>
>>>> so, for any month that is not 31 days, I want to delete the row
>>>> accordingly.
>>>>
>>>> The question is, I have data sets from year 1970-2013, and to delete
>>>> manually it would be time consuming, so how do I delete those rows
>>>> according to the
>>>>
>>>> 1) month itself
>>>> 2) leap years ( year that is categorized
>>>> as
>>>> leap year, should
>>>> have
>>>> 29 days in Feb)
>>>>
>>>> Hope you can help me. Thanks a lot.
>>>>
>>>> Regards,
>>>> Dila
>>>
>>>________________________________
>>>Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
>>>Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
>>>Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
>>>Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.
>>>
>>>V případě, že je tento e-mail součástí obchodního jednání:
>>>- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
>>>- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
>>>- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
>>>- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.
>>>
>>>This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
>>>If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
>>>If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
>>>The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.
>>>
>>>In case that this e-mail forms part of business dealings:
>>>- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
>>>- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
>>>- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
>>>- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
>>>
>>
>
More information about the R-help
mailing list